Yuu
Yuu

Reputation: 619

Access to the path is denied in ASP.NET MVC

I was trying to Create a Directory using this code:

Directory.CreateDirectory("localhost/attachments/7075");

But it returned 'Access to the path 'localhost/attachments/7075' is denied.'

Please take note that the attachments is from a Network Shared Folder. I added it using the Add Virtual Directory on IIS.

What I did is:

Upvotes: 0

Views: 1028

Answers (1)

user3559349
user3559349

Reputation:

You need to use Server.MapPath() to use the physical file path that corresponds to the virtual path.

Directory.CreateDirectory(Path.Combine(Server.MapPath("~/attachments"), "7075"));

Upvotes: 2

Related Questions