EPiWiki.se  - EPiServer notes shared with others


Sample how to use EPiServers CMD LinkCollection property in a more advanced way.

Extract page references

This example extract page references from a LinkCollection.

public static EPiServer.Core.PageReferenceCollection GetLinks(LinkItemCollection value)
   EPiServer.Core.PageReferenceCollection ret = new PageReferenceCollection();
   foreach (LinkItem link in value)
      Guid id = EPiServer.Web.PermanentLinkUtility.GetGuid(link.Href);
      PageReference pageLink =

      if (PageReference.IsNullOrEmpty(pageLink))
         //This sample only extract page references


   return ret;

Programmatically update a LinkCollection

A sample to programmatically add the start page to existing LinkCollection

Var toPage = DataFactory.Instance.GetPage(PageReference.StartPage));
var existingLink = page[Tag.RelatedPages] != null
                ? (LinkItemCollection)page.Property[Tag.RelatedPages].Value
                : new LinkItemCollection();
PageData pd = page.CreateWritableClone();
existingLink.Add(new LinkItem() { Text = toPage.PageName, Href = toPage.LinkURL });
DataFactory.Instance.Save(pd, SaveAction.Publish, AccessLevel.NoAccess);

Version author:
Mattias Lövström

EPiServer version

'CMS 5 R2'