Language: C#
Get all pages from a link collection property as a populated PageDataCollection in EPiServer
1: /// <summary> 2: /// Get all pages from the LinkItemCollection property 3: /// </summary> 4: /// <returns>PageDataCollection</returns> 5: public PageDataCollection GetLinkCollectionPages(string propertyName) 6: { 7: PageDataCollection pages = new PageDataCollection(); 8: LinkItemCollection links = CurrentPage[propertyName] != null ? CurrentPage.Property[propertyName].Value as LinkItemCollection : null; 9: if (links != null) 10: { 11: PageReference pageRef; 12: PageData page; 13: foreach (LinkItem item in links) 14: { 15: UrlBuilder url = new UrlBuilder(item.Href); 16: bool result = PermanentLinkMapStore.ToMapped(url); 17: pageRef = result ? PageReference.ParseUrl(url.ToString()) : PageReference.EmptyReference; 18: if (!PageReference.IsNullOrEmpty(pageRef)) 19: { 20: page = DataFactory.Instance.GetPage(pageRef); 21: if (page != null) 22: { 23: pages.Add(page); 24: } 25: } 26: } 27: } 28: return pages; 29: }
Tags:
Description:
Method on an EPiServer page with the purpose of getting all links in a link collection property as pages in a populated PageDataCollection
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

