EPiServer Extension Methods part 2
Posted on June 16, 2009 by Frederik Vig in EPiServerEPiServer 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);

Martin S. says:
Post Author June 30, 2009 at 12:49Excellent code snippet, that’s very useful. LinkItemCollection is neat to use.
Amari says:
Post Author May 16, 2011 at 14:53Wonderful blog you have right here but I was questioning in the event you realized of any local community message boards that cover the very same topics talked about during this article? Id actually appreciate to be a part of group exactly where I will get feedback from other well-informed individuals that share the identical interest. For those who have any recommendations, make sure you allow me to know. Enjoy it!