Access to the path is denied

Access to the path 'C:\inetpub\wwwroot\mysite\images\savehere' is denied

Read the message carefully. You are trying to save to a file that has the same name as the directory. That cannot work, you can't overwrite a directory filled with files with a single new file. That would cause undiagnosable data loss, "Access to the path is denied" is the file system fighting back to prevent that from happening.

The exception message is not ideal, but it comes straight from the OS and they are cast in stone. The framework often adds extra checks to generate better messages, but this is an expensive test on a network. Perf is a feature too.

You need to use a name like 'C:\inetpub\wwwroot\mysite\images\savehere\mumble.jpg'. Consider Path.Combine() to reliably generate the path name.


You need to find out from the application pool for the website what is the identity it is running under (by default this is Application Pool Identity) and grant that the correct permissions.

Tags:

C#

.Net

Iis

Path