London Dev Meetup Rescheduled! Due to unavoidable reasons, the event has been moved to 21st May. Speakers remain the same—any changes will be communicated. Seats are limited—register here to secure your spot!

HostingEnvironment.VirtualPathProvider.FileExists(path) always false.

Vote:
0

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
Vote:
0

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
Vote:
0

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
Vote:
0
return mf != null && mf.BinaryData != null;

;)

#120232
Apr 13, 2015 23:17
Vote:
0

Sure thing ;)

#120259
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.