Try our conversational search powered by Generative AI!

LinkItem and files

Vote:
 

I'm looking to retrieve the ContentReference for a file in a LinkItem, but I'm struggling on how to do it. ContentReference.Parse seems only to work when the LinkItem refers to a page.

Anyone who has any pointers on where to look?

#90656
Sep 15, 2014 14:52
Vote:
 

This code should work. However, haven't tried it on files.

string mappedUrl;

if (PermanentLinkMapStore.TryToMapped(linkItem.Href, out mappedUrl))
{
    var url = new UrlBuilder(mappedUrl);

    var contentReference = PermanentLinkUtility.GetContentReference(url);
}

But I guess there is new and better approach, maybe with UrlResolver...

#90662
Sep 15, 2014 17:52
Vote:
 

Hi Tobias,

The way of Johan is very nice but I think you can base on LinkItem to get it easier:

var mappedHref = linkItem.GetMappedHref();
var contentReference = EPiServer.Web.PermanentLinkUtility.GetContentReference(new UrlBuilder(mappedHref));

// Ha Bui

#90665
Sep 16, 2014 4:28
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.