Media Item by path

Vote:
 

Previously I could open a VersioningFile using:

var fileVersion = (VersioningFile)HostingEnvironment.VirtualPathProvider.GetFile(imagePath);

How can I do the same thing in the new media system?

#86458
May 22, 2014 6:17
Vote:
 

Hi Bevan,

Here's the code:

var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();

IContent content = urlResolver.Route(new UrlBuilder(imagePath));
// cast to MediaData, or ImageFile, or whatever :)
var mediaData = content as MediaData;

Hope this helps

#86481
Edited, May 22, 2014 13:02
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.