Try our conversational search powered by Generative AI!

HostingEnvironment.VirtualPathProvider.FileExists(path) always false.


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?

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!


Apr 13, 2015 19:30

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;
Apr 13, 2015 21:46
return mf != null && mf.BinaryData != null;


Apr 13, 2015 23:17

Sure thing ;)

Apr 14, 2015 11:06
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.