Frederik Vig – ASP.NET developer

Follow me

EPiServer Extension Methods part 2

EPiServer Extension Methods part 1

From LinkItemCollection to PageDataCollection

public static PageDataCollection ToPageDataCollection(this LinkItemCollection linkItemCollection)
{
    var pageDataCollection = new PageDataCollection();
    foreach (var linkItem in linkItemCollection)
    {
	var url = new UrlBuilder(linkItem.Href);
	bool isEPiServerPage = PermanentLinkMapStore.ToMapped(url);
 
	if (isEPiServerPage)
	{
	    var page = DataFactory.Instance.GetPage(PermanentLinkUtility.GetPageReference(url));
 
	    if (page != null)
	    {
		pageDataCollection.Add(page);
	    }
	}
    }
 
    return pageDataCollection;
}

Example

if (IsValue("RelatedPages"))
{
    var relatedLinkItems = (LinkItemCollection) CurrentPage["RelatedPages"];
    if (relatedLinkItems != null)
    {
         var relatedPages = relatedLinkItems.ToPageDataCollection();
         if (relatedPages != null)
         {
             rptRelatedContent = relatedPages;
             rptRelatedContent.DataBind();
         }
    }
}

This is great since you now have the ability to filter out the pages that the user does not have access to or that are not published.

FilterForVisitor.Filter(relatedPages);

Related Posts:

Share:
  • Twitter
  • DotNetKicks
  • DZone
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • StumbleUpon
  • Digg

One Comment

  1. Martin S. says:

    Excellent code snippet, that’s very useful. LinkItemCollection is neat to use.

Leave a Reply

Spam Protection by WP-SpamFree

© Copyright Frederik Vig. Based on Fluid Blue theme