Get friendly URL out of a local file name



I have a file stored in the Global Files VPP. I know the local file name of this file (for example "d:\EPiServer\VPP\SimpleEPiServer6\Global\44\7f\447f7232-e9d8-49e9-bbd6-a5d67ab25a59.jpg"). The file is not referenced on the site. I need to convert the file name to a friendly URL. This is done by the built in File Manager when you browse the Global Files structure.

The local file name ("447f7232-e9d8-49e9-bbd6-a5d67ab25a59.jpg") is the local file name; it's not stored as a soft link, so I can't look it up by using EPiServer.Global.UrlRewriteProvider.ConvertToExternal().

So basically, I'm looking for how to convert 447f7232-e9d8-49e9-bbd6-a5d67ab25a59.jpg to /Global/MyImage.jpg (or whatever the friendly URL will look like).

If anyone knows how to solve this I'd be grateful.


Feb 20, 2013 7:56

Call PermanentLinkMapStore.Find and pass in your guid.

On the PermanentLinkMap you get back as result there is a property MappedUrl which is what you are looking for.

Feb 20, 2013 8:28

Hello Johan

Thanks for the response. However it didn't work. Remember I only have the local file name GUID. It's not the same as a GUID stored in the tblPageSoftlink.

The Find() method returns null in my case.

Any more ideas?

Feb 20, 2013 9:25

Ok, now I understand. The guid you have is actually the guid to a specific version of a file. In that case I think you would need to go towards Object Store (thats where metadata for files are stored) and load the related FileItem and then use that to resolve the url. Something like:

Guid versionId = new Guid("{your guid}");
ISession session = EPiServer.BaseLibrary.Context.Current.Repository.CreateSession();
var file = session.RelatedItemsTo<FileItem>(versionId).FirstOrDefault();
if (file != null)
string furl = PermanentLinkMapStore.Find((Guid)file.Id).MappedUrl.ToString();

Feb 22, 2013 16:50

Hello again Johan,

superb, that was exactly what I was looking for. Thank you!


Feb 25, 2013 14:45
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.