Try our conversational search powered by Generative AI!

LinkUrl type property for Media file

Vote:
 

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.

#230604
Edited, Nov 09, 2020 19:37
Vote:
 

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.

#230625
Nov 09, 2020 23:46
Vote:
 

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 ?

#230646
Nov 10, 2020 15:32
Vote:
 

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

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

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 "-".

#230651
Edited, Nov 10, 2020 16:42
Vote:
 

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.

#230679
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.