C# MVC Access to path denied when trying to write file

TheGuest picture TheGuest · Oct 1, 2011 · Viewed 9.7k times · Source

I have an MVC application in which users are able to upload files. Before I write the uploaded file, I create a directory according to date time. I start off with C:\ApplicationName and end up with C:\ApplicationName\20111001\Filename.ext when the upload is completed (in theory).

My problem on my local Windows 7 machine is that I can not write the file.

I get an "access denied" exception no matter which user I give full access to the directory. The strange thing is that the date directory gets created just fine.

I have given the following users full access:

  • [Current logged in user]
  • NETWORK SERVICE
  • IUSR
  • IIS_IUSRS
  • Guests
  • Everyone

Without any success. I really don't understand what is going on here. When I give Everyone full access, I should be able to create a file right?

PS: I use Visual Studio 2010 and ASP.NET Development Server straight out of the box.

Answer

ryudice picture ryudice · Oct 1, 2011

Check the permissions of the parent folder and make sure they are inheritable, you can check this on the advance options window.