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.

    http://world.episerver.com/documentation/Class-library/?documentId=cms/7/f590c418-4e1f-6d94-c1a0-d806a9ebd0e4

    Hope this helps!

    /T

    #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