I thought that function was default EPiServer. Here it is:
public static class LinkItemCollectionUtility
{
public static PageDataCollection ToPageDataCollection(this LinkItemCollection linkItemCollection)
{
var pageDataCollection = new PageDataCollection();
foreach (var linkItem in linkItemCollection)
{
var url = new UrlBuilder(linkItem.Href);
if (PermanentLinkMapStore.ToMapped(url))
{
var page = DataFactory.Instance.GetPage(PermanentLinkUtility.GetPageReference(url));
if (page != null)
{
pageDataCollection.Add(page);
}
}
}
return pageDataCollection;
}
}
The code looks fine. Only way it should return false is for external links, e-mail address, documents etc. Are you sure this is an internal link?
I'm debugging in Visual Studio and the URL is a object, where 'uri' is the above url.
Yes, but since it is returning false EPiServer cannot find it in its database. Try readding the pages in the LinkItemCollection property in edit mode and see if that makes a difference.
PermanentLinkMapStore is used to convert between the permanent link format (e.g. ~/link<guid>.aspx) to the "classic" format (e.g. /templates/pages/page.aspx?id=7).
In your example the url is in the FURL format, to get the page from that format you could instead of PermanentLinkMapStore use Global.UrlRewriteProvider.TryConvertToInternal. The second out parameter will in case of a match typically be the PageReference to the page.
I'm trying to use 'ToPageDataCollection()' to get a list of links and add this to my repeater.
The problem is that the function 'PermanentLinkMapStore.ToMapped(url)' inside 'ToPageDataCollection' returns false.
More exactly this is not working:
var url = new UrlBuilder(linkItem.Href); // url is now {http://localhost.mysite.no/Big/House/}
PermanentLinkMapStore.ToMapped(url); // This returns false. Why?
This is the code I use to get link list and use it as a datasource for my repeater:
var relatedLinkItems = CurrentPage["shortcutList"] as LinkItemCollection;
var relatedLinkPages = relatedLinkItems.ToPageDataCollection();
relatedLinkPages = FilterForVisitor.Filter(relatedLinkPages);
var pages = FilterForVisitor.Filter(relatedLinkPages);
rptshortcutList.DataSource = pages;
rptshortcutList.DataBind();