Auto-creating folder per site


We are using the VirtualPathProvider stuff to get a files uploaded by the editor of a site, using File Manager.

 We will have a folder per site in out Enterprise installation og EPiServer.

 What I would like to be able to do is auto create the folder if it is not there. I have some code to do this but it seems a little flaky and I doubt the right permissions will be set.


I am using this code 

// Rewrite path to the VPP folder for the site
string siteId = Settings.Instance.Parent.SiteId;

// Create config
NameValueCollection config = new NameValueCollection() {
{"showInFileManager", bool.TrueString},
{"virtualName", siteId},
{"name", siteId},
{"maxVersions", "15"},
{"bypassAccessCheck", bool.FalseString},
{"virtualPath", string.Format("~/{0}/", siteId)},
{"physicalPath", string.Format(@"\\NWPBIZTFS02\VPP$\Dev\{0}", siteId)}

EPiServer.Web.Hosting.VirtualPathVersioningProvider siteSpecificVpp = new VirtualPathVersioningProvider(siteId, config);

// Register provider then update mappings so that it will appear in the File Manager correctly

VirtualPathUnifiedProvider siteSpecific = siteSpecificVpp as VirtualPathUnifiedProvider;
if (siteSpecific != null)
string absolutePath = VirtualPathUtility.AppendTrailingSlash(VirtualPathUtilityEx.ToAbsolute(config["virtualPath"]));

if (VirtualPathHandler.Instance.NameToVirtualPathMapping.ContainsKey(config["name"]) == true)
VirtualPathHandler.Instance.NameToVirtualPathMapping[config["name"]] = absolutePath;
KeyValuePair nameToPathMapping =
new KeyValuePair(config["name"], absolutePath);

if (VirtualPathHandler.Instance.VirtualPathToNameMapping.ContainsKey(absolutePath) == true)
VirtualPathHandler.Instance.VirtualPathToNameMapping[absolutePath] = config["virtualName"];
KeyValuePair pathToNameMapping =
new KeyValuePair(absolutePath, config["virtualName"]);

Does anyone have a better idea?



Pat Long



Jan 05, 2009 9:06
* 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.