Try our conversational search powered by Generative AI!

VirtualPathUnifiedProvider is null

Vote:
 

Hi,

I have a fresh install of EPi 6 with Composer and in my code I am doing the following:

vpp = System.Web.Hosting.HostingEnvironment.VirtualPathProvider as VirtualPathUnifiedProvider;

if (vpp != null)

{

// do some stuff

}

However vpp is always null, is there a basic setting etc that I am blindly missing :-)

Thanks a in advance

#41958
Aug 04, 2010 18:30
Vote:
 

I might be mistaken, but it seems like you're just casting a class to another class, which make no sense. You're missing the actual vpp object. What are you trying to achieve?

#41962
Aug 05, 2010 9:43
Vote:
 

How did you solve this?

#66343
Feb 27, 2013 13:51
Vote:
 

VirtualPathProviders are "chained" together (they have a property Previous that points to next in chain). System.Web.Hosting.HostingEnvironment.VirtualPathProvider will just point to the last in chain which might or might not be a VirtualPathUnifiedProvider (depending on which is registered last in your configuration).

If you are looking for getting a handle to a specific VirtualPathUnifiedProvider my suggestion is to use EPiServer.Web.Hosting.VirtualPathHandler.Instance.VirtualPathProviders where you can find the provider you are looking for.

#66347
Feb 27, 2013 14:11
Vote:
 

Hello Johan, thank you for your fast answer, for my case, it is a VirtualPathNativeProvider, still it is null, even UnifiedFile casts are null. How am i suppose to do? customFile is null in this example.

 ICollection<VirtualPathProvider> vpppp = EPiServer.Web.Hosting.VirtualPathHandler.Instance.VirtualPathProviders.Keys;

                    UnifiedFile customFile = null;
                    foreach (var x in vpppp)
                    {
                        VirtualPathNativeProvider x2 = x as VirtualPathNativeProvider;
                        if (x2!=null && x2.ProviderName == "ImageBank")
                        {
                            VirtualFile vf = x2.GetFile(path);
                            customFile = vf as UnifiedFile;

                        }
                    }
    VirtualPathNativeProvider vpp = System.Web.Hosting.HostingEnvironment.VirtualPathProvider as VirtualPathNativeProvider

    

#66359
Feb 27, 2013 15:05
Vote:
 

To get a file you should not need to call to a specific provider, since they are chained you should call the first and that one will send it to next in chain until a provider hanldes the file or null if no provider handles the file.

So if you call:

var file = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetFile(path)

what do you get back? Typically if no provider matches you get an instance of MapPathBasedVirtualFile.

What does your path look like? It should be a relative path like for example /Global/MyFile.jpg or ~/Global/MyFile.jpg

#66360
Feb 27, 2013 15:13
Vote:
 

oh, i get it, but i do get a VirtualFile, but when i cast it to UnifiedFile it is null. Any Ide?

Strange behavior, the code below works though:

  UnifiedDirectory directory = System.Web.Hosting.HostingEnvironment.VirtualPathProvider.GetDirectory(originalsPath) as UnifiedDirectory;

    

#66391
Feb 27, 2013 21:24
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.