Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exception: System.UnauthorizedAccessException: Access to the path "C:\

Status
Not open for further replies.

ace333

Programmer
Jul 12, 2005
105
CH
I'm getting this error in an application that I'm 100% sure was working half an hour ago. I'm working on a project on a stand alone p.c. so issues with security access to the file i am trying to read should not be an issue. I created the files et cetera.
This is the error
Exception: System.UnauthorizedAccessException: Access to the path "C:\Documents and Settings\nnichol1\Desktop\testXSD.xsd" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) at System.Xml.XmlTextReader.CreateScanner() at System.Xml.XmlTextReader.Init() at System.Xml.XmlTextReader.Read() at System.Xml.XmlValidatingReader.ReadWithCollectTextToken() at System.Xml.XmlValidatingReader.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at Project1.xmlApp.btnValidate_Click(Object sender, EventArgs e) in c:\inetpub\ 86
 
It looks to me... like you opened an xml file and then your app died before closing the file properly.

Remeber to use Try Catch Finally to deal with files.

try
{
//open file and use it as needed
}
catch (exception ex)
{
//handle the exception if one is thrown
}
finally
{
//close the file.
}
 
I put this in the web config and it seems to have worked so far

<identity impersonate="true"/>
 
I don't believe it, the problem i though i had solved is back. I though the above worked but it didnt. I have no idea what is going on.

Exception: System.UnauthorizedAccessException: Access to the path "C:\Temp\test.xml" is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String str) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials) at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn) at System.Xml.XmlTextReader.CreateScanner() at System.Xml.XmlTextReader.Init() at System.Xml.XmlTextReader.Read() at System.Xml.XmlValidatingReader.ReadWithCollectTextToken() at System.Xml.XmlValidatingReader.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at Project1.xmlApp.btnValidate_Click(Object sender, EventArgs e) in c:\inetpub\ 98



PLEASE HELP
 
You can get this if you stop debugging in the middle of a debug session -- the OS doesn't know the file isn't being used anymore. You can usually solve it by restarting your IDE. If not, a reboot may be needed.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Ya tried all that, still the same thing keeps happening, i think i'm goijg ccrazy
 
with this... "I put this in the web config" I am assuming this is an ASP.NET app.

In that case the access violation is happening becuase "you" are not the one who is trying to open the file. The asp.net worker process is the one trying to open the file. You will have to grant access to the ASPNET user if XP and if Win2003 whatever user you have the app pool running under to the folder where your file is located.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top