我有一个会员注册aspx页面。

ACCOUNT(user,pass,mail,privilege)


成功注册用户后,如果privilege == "lecturer"->会创建一个文件夹,其中folder's name= user

看下面我的代码:

 if(privilege=="lecturer")
        {
            string path = this.Server.MapPath("~/Lecturer/"); // path="D:\\C#Projects\\website\\Lecturer\\"
            string targetPath = path + @"\";
            System.IO.Directory.CreateDirectory(Server.MapPath(targetPath+newuser));

        }


它有一个错误:'D:/C#Projects/website/Lecturer/david' is a physical path, but a virtual path was expected.为什么???

我真的很想在Lecturer文件夹中创建一个david文件夹。救命???

最佳答案

您已将虚拟路径转换为物理路径,因此无需再次使用Server.MapPath

更改

 System.IO.Directory.CreateDirectory(Server.MapPath(targetPath+newuser));




 System.IO.Directory.CreateDirectory(targetPath+newuser);

关于c# - 通过代码创建文件夹时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19453015/

10-11 12:02