CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

Get all pages from a link collection property as a populated PageDataCollection in EPiServer

478 Views
Copy Code Show/Hide Line Numbers
   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:  }
by rawbert
  December 08, 2009 @ 7:41am
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

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate