Try our conversational search powered by Generative AI!

Auto-creating folder per site

Vote:
 

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
GenericHostingEnvironment.RegisterVirtualPathProvider(siteSpecificVpp);

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;
}
else
{
KeyValuePair nameToPathMapping =
new KeyValuePair(config["name"], absolutePath);
VirtualPathHandler.Instance.NameToVirtualPathMapping.Add(nameToPathMapping);
}

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

Does anyone have a better idea?

Thanks

 

Pat Long

 

 

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