1

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???

1

2 Answers 2

3

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); 
Sign up to request clarification or add additional context in comments.

Comments

1

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); 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.