Reputation: 878
I have a Member Register aspx page.
ACCOUNT(user,pass,mail,privilege)
When a user is registerd sucessfully, if the privilege == "lecturer"
--> a folder is created which folder's name= user
.
Take a look at my code below:
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));
}
It has an error: 'D:/C#Projects/website/Lecturer/david' is a physical path, but a virtual path was expected.
Why???
I really want to create a david folder in Lecturer folder. Help???
Upvotes: 1
Views: 762
Reputation: 172618
If you already have a physical path D:\\C#Projects\\website\\Lecturer\\
, it doesn't make sense to call Server.MapPath
You can try this:-
var files = Directory.GetFiles(@"D:\C#Projects\website\Lecturer");
or simply try this:-
System.IO.Directory.CreateDirectory(targetPath+newuser);
Upvotes: 1
Reputation: 148180
You do not need to use Server.MapPath
again as you have already converted the virtual path to physical path.
Change
System.IO.Directory.CreateDirectory(Server.MapPath(targetPath+newuser));
To
System.IO.Directory.CreateDirectory(targetPath+newuser);
Upvotes: 3