Get the link for MediaData or AssetFolder in 7.5

Vote:
 

Lets say I have the ContentReference for a file, a MediaData.

Ok, so how can I get the link to this file?

Didn't find much info in SDK or 7.5 pages on World...

 

Same goes with the AssetsFolder, how get the link?

 

I have played around with:

var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var folder = contentRepository.GetDefault<ContentAssetFolder>(pub.AssetFolder);

    

but the folder object doesn't contain much

Any advice would be appreciated!

 

#78865
Dec 04, 2013 13:38
Vote:
 

You could use UrlResolver (resides in EPiServer.Web namespace), you can either get an instance from IOC container or use static property Current. 

UrlResolver have several overloaded methods GetUrl that returns links. The most basic one takes a single ContentReference and returns the url in the same format as the current context is executing (so if the code executes on site the url will be public while if the code is executign e.g. in onpageedit mode the url will be in edit format.)

#78870
Dec 04, 2013 14:06
Vote:
 

Great !

looked forever for that

#80659
Jan 28, 2014 17:39
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.