Try our conversational search powered by Generative AI!

LinkUrl type property for Media file


Is there a property that is equivalent to LinkUrl for PageData. The need I have is to provide a constant URL (Permalink) to pdf files so even if they were moved from one directory to other in Media, there is still a link that takes me to the PDF.

Converting a media file to Icontent doesn't have the LinkUrl.

Edited, Nov 09, 2020 19:37

Don't think there is a function to get the permanent link. But you can easily create one on your own with following format: /link/{content guid}. The content guid is available on all content items.

Nov 09, 2020 23:46

Hi Johan

I am not sure creating such link for media files (pdf) will take me to the actual content.  I tried your suggestion but I get 404. Am i missing something ?

Nov 10, 2020 15:32

It should work. Maybe the format of the guid is important(?)

var permanentLink = $"/link/{content.ContentGuid:N}";
Nov 10, 2020 16:22

Thanks Johan. It was my mistake as I was appending .pdf to the link whereas it should be either .aspx or nothing at all. Also yes the format of guid is important as it should not contain the "-".

Edited, Nov 10, 2020 16:42

I would add here that don't forget the EPiServer.Web.PermanentLinkUtility from EPiServer assembly ;) as it has the method for you that does exactly what the suggested format string from Johan (well with a little twist :D)

string permanentLinkUrl = PermanentLinkUtility.GetPermanentLinkVirtualPath(your-content-here.ContentGuid, ".aspx");

The last argument is the extension you want to have for the created url (and it must include the dot), but if you leave it as null or string empty you will get the "extensionless" url.

Nov 11, 2020 7:13
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.