Asp.net mvc 在MVC中上载动态创建文件夹
VS'12 iNet应用程序模板asp.net C#MVC4,EF代码优先 上传帖子方法 我的问题是Asp.net mvc 在MVC中上载动态创建文件夹,asp.net-mvc,file-upload,permissions,directory,file-management,Asp.net Mvc,File Upload,Permissions,Directory,File Management,VS'12 iNet应用程序模板asp.net C#MVC4,EF代码优先 上传帖子方法 我的问题是 为什么不创建我的文件夹 当我(欺骗并自己制作)我没有权限 如何才能最好地动态上传(我想单独保存上传的文件) 有没有更好的方法来管理它们 这适用于通过IIS在开发人员计算机上以及在我的服务器上IIS使用Server.MapPath(strMappath)创建文件夹并检查是否存在 if (ModelState.IsValid) { fo
Server.MapPath(strMappath)
创建文件夹并检查是否存在
if (ModelState.IsValid)
{
foreach (var file in attachments)
{
string strMappath = "~/UploadedImages/" +var1+ "/" + var2+ "/" + var3+ "/" + var4+ "/" + var5 + "/";
if (!Directory.Exists(strMappath))
{
DirectoryInfo di = Directory.CreateDirectory(strMappath);
}
// Some browsers send file names with full path. We only care about the file name.
//var fileName = Path.GetFileName(file.FileName);
var fileName = Path.GetFileNameWithoutExtension(file.FileName) + Path.GetExtension(file.FileName);
var destinationPath = Path.Combine(
Server.MapPath(strMappath), fileName);
file.SaveAs(destinationPath);
}