Link to home
Start Free TrialLog in
Avatar of justdriveon
justdriveon

asked on

Can't create or write to a file w/ASP.NET: UnauthorizedAccessException

I have a C# ASP.NET 2.0 application that needs to write some simple logging records to an XML file in the bin directory under the www root.  If I attempt to create or write to the file, I get an UnauthorizedAccessException.  (Access to the path 'D:\webadmin\www\bin\test.xml' is denied).  My server administrator says the ASP.NET user has write access to the bin directory, and I'm not sure what else the problem could be.

My testing code...  this code is compiled code-behind in the bin directory (same directory I'm trying to write to) and the ASPX page is up one directory (under the root).


filepath = @"D:\webadmin\www\bin\test.xml"
if (!File.Exists(filepath)) {
      File.Create(filepath); //Error is thrown here.
}
ASKER CERTIFIED SOLUTION
Avatar of _TAD_
_TAD_

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of justdriveon
justdriveon

ASKER

Even though the I had read and used the error description for this error as reiterated by _TAD_, his comment prompted me to go back to my server guy and tell him to look again.  Turns out he was checking permissions on the wrong website.  Isn't it nice when the problem is someone else's rather than your own?

I am also giving Kate12 points because when googling this problem I could not find anything about these FileSecurity/FolderSecurity classes, only Active Directory Server as in this arcticle: http://support.microsoft.com/kb/899553/EN-US/.  So even though I didn't use it, I probably would have been able to solve the problem this way.