Try our conversational search powered by Generative AI!

List of all Virtual Page Providers

Vote:
 

What would be the easiest way of programmatically obtaining a list of all available VPP's and its properties in web.config?

In effect, this is the pseudo code of what I would like:

string s = "";
foreach(VirtualPageProvider vpp in myVirtualPageProviderCollection) { s += string.Format("VirtualName: {0}, VirtualPath: {1}", vpp.VirtualName, vpp.VirtualPath); }
#25356
Oct 22, 2008 13:43
Vote:
 

Something like this 

using System.Collections.Generic;
using System.Configuration;
using System.Web.Hosting;
using EPiServer.Web.Hosting;

VirtualPathHandler virtualPathHandler = VirtualPathHandler.Instance;
foreach (KeyValuePair<VirtualPathProvider, ProviderSettings> keyValuePair in virtualPathHandler.VirtualPathProviders)
{
    Response.Write("<p>" + String.Format("Name: {0}, VirtualName: {1}, VirtualPath: {2}, Type: {3}", (keyValuePair.Value as ProviderSettings).Name, (keyValuePair.Value as ProviderSettings).Parameters["virtualName"], (keyValuePair.Value as ProviderSettings).Parameters["virtualPath"], (keyValuePair.Key as VirtualPathProvider).GetType().FullName) + "</p>");
}

Hope it helps

/Hans

#25382
Oct 23, 2008 10:02
Vote:
 

Thanks for your reply, but I get an error with that code. EPiServer.Web.Hosting.VirtualPathHandler does not seem to contain a definition for "VirtualPathProviders" - as in "virtualPathHandler.VirtualPathProviders" in the foreach above. I'm using CMS R1 SP3. Maybe this works with R2?

By the way, also thanks for posting the code without using the code snippet function in this editor, unlike me... your way makes the code more readable

/Marten

#25385
Oct 23, 2008 12:02
Vote:
 

Ok, made it with R2.

Maybe you can use:
foreach(KeyValuePair<String, String> in VirtualPathHandler.Instance.VirtualPathToNameMapping)

See what you get and then maybe use VirtualPathHandler.GetProvider(String providerName)

Havent tried though

/Hans

#25389
Oct 23, 2008 12:44
Vote:
 

This loops throu all the VPP folders 

public List<VirtualFile> GetAllFiles()
        {
            VirtualPathElement virtualPathSettings = EPiServerSection.Instance.VirtualPathSettings;
            VirtualPathHandler instance = VirtualPathHandler.Instance;
            instance.CustomFileSummary = virtualPathSettings.CustomFileSummary;
            instance.InitializeProviders(virtualPathSettings.Providers);
            instance.InitializeFilters(virtualPathSettings.Filters);
            List<VirtualFile> allFiles = new List<VirtualFile>();

            foreach (string key in instance.NameToVirtualPathMapping.Values)
            {
              
                DigFiles(instance.GetDirectory(key, false), allFiles);
            }
            return allFiles;
        }

#25411
Oct 23, 2008 23:21
Vote:
 
Thanks a lot, will try this!
#25412
Oct 23, 2008 23:27
* 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.