ASP.NET MVC3中如何创建文件夹

string mapPath=Server.MapPath("/image/newDir");if (!Directory.Exists(mapPath)) { Directory.CreateDirectory(mapPath);}这样为什么创建不了文件夹?

第1个回答  2013-05-22
string filePhysicalPath = Server.MapPath("~/image/newDir/");
if (!Directory.Exists(filePhysicalPath))//判断上传文件夹是否存在,若不存在,则创建
{
Directory.CreateDirectory(filePhysicalPath);//创建文件夹
}

这样才可以的哦,关键在这个“~”符号
相似回答