private string CreateWebRootFile(XFormControl form, HttpPostedFile _postedFile, string formName, string oldFiles)
{
var _uploadedFileName = _postedFile.FileName;
var dir = CreatePathToSaveIn("PATH GOES HERE");
if (dir != null)
{
var fileName = Path.GetFileName(_uploadedFileName);
var _file = form.Page.Request.Files[formName + "FileUpload"];
if (_file != null)
{
_file.SaveAs(dir + fileName);
}
_uploadedFileName = "Somepath here";
if (oldFiles != String.Empty)
{
oldFiles += "|";
}
oldFiles += _uploadedFileName;
}
return oldFiles;
}
private UnifiedDirectory CreatePathToSaveIn(string path)
{
var dir = HostingEnvironment.VirtualPathProvider.GetDirectory(path) as UnifiedDirectory;
if (dir == null)
{
var tmpPath = "/";
foreach (var part in path.Split("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))
{
tmpPath += part + "/";
var tmp = HostingEnvironment.VirtualPathProvider.GetDirectory(tmpPath) as UnifiedDirectory;
if (tmp != null)
dir = tmp;
else if (dir != null)
{
dir.BypassAccessCheck = true;
dir = dir.CreateSubdirectory(part);
}
}
}
return dir;
Friday, May 22, 2015
EpiServer - Save XForm File To VPP Example
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment