HostingEnvironment.VirtualPathProvider.FileExists(path) always false.

Member since: 2007

Hi all,

Ugrade from CMS6r2 to 7.19.2 (webforms)

I want to check if image Exists on disc.

HostingEnvironment.VirtualPathProvider.FileExists("/globalassets/penguins.jpg") always false. (the image is there on the site)

EPiServer.Web.Hosting.VirtualPathHandler.GetProvider("SiteGlobalFiles") is null. (How do i know what the name is? since it is not in the episerverframework.config)

the images are working on the site.

Any Idea?

#120180 Apr 13, 2015 11:57
  • Hi Lucster,

    In 7.5 we switched from using VPP for media files and instead use the new media system (which now uses a blob provider to store files). Now files are content just like pages. You can get a content reference from a URL by using the UrlResolver.

    Hope this helps!


    #120206 Apr 13, 2015 19:30
  • Member since: 2007

    Thanks Tony! that helped. So the approach is something like this:

    Public bool FileExists(string path){
     var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();
                    UrlBuilder url = new EPiServer.UrlBuilder(path);
                    var content = urlResolver.Route(url);
                    MediaData mf = content as MediaData;
                    if (mf != null && mf.BinaryData != null)
                        return true;
                    return false;

    #120227 Apr 13, 2015 21:46
  • Member since: 2011
    return mf != null && mf.BinaryData != null;


    #120232 Apr 13, 2015 23:17
  • Member since: 2007

    Sure thing ;)

    #120259 Apr 14, 2015 11:06
This topic is locked because the last reply was posted more than 6 months ago. Please contact to unlock it.