ace333 Posted July 19, 2005 Posted July 19, 2005 Exception: System.UnauthorizedAccessException: Access to the path "C:\Temp\test.xml" This was working okay, gave me a problem , thought i had solved it with the following line of code in the web.config file (added <identity impersonate="true"/>) but now the problem is back. This is the method that is giving me the problem, so one said that i may need a finally after the catch section to close the stream that i am opening but i am doing that already at the end of the try section. public void btnValidate_Click(object sender, System.EventArgs e) { if(inFileLocation.Value == "") { lblfileLoc.Visible = true; } int error = 0; try { String loc = inFileLocation.Value; //Response.Write(loc); loc.Replace(@"\",@"\\"); //Response.Write(loc); // Load a document with an inline schema XmlTextReader xtr = new XmlTextReader(loc); // Prepare to validate it XmlValidatingReader xvr = new XmlValidatingReader(xtr); xvr.ValidationType = ValidationType.Schema; // Tell the validator what to do with errors xvr.ValidationEventHandler += new ValidationEventHandler(ValidationHandler); // Load the document, thus validating XmlDocument xd = new XmlDocument(); xd.Load(xvr); // Clean up xvr.Close(); } catch (XmlException ef) { error = 1; lblErrors.Visible = true; lblErrors.Text = "XmlException: " + ef.ToString(); } catch (Exception eg) { error = 1; lblErrors2.Visible = true; lblErrors2.Text ="Exception: " + eg.ToString(); } finally { //may be needed !!! } if (error == 0) { lblValidated.Visible = true; btnValidate.Enabled = false; btnRead.Enabled = true; lblErrors.Visible = false; lblErrors2.Visible = false; lblErrors3.Visible = false; } }//End of upload method. public void ValidationHandler(object sender, ValidationEventArgs e) { // Dump any validation errors to the UI lblErrors3.Visible = true; lblErrors3.Text = e.Message; } 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\wwwroot\project1\xmlapp.aspx.cs:line 98 This section gives the following block of ugly errors, i've already spend about 3 hours on the problem and they all give the same solution about changing the permissions on the file. But I am already the creator of the file, and the groups that others have talked about like the network group are there already... Could some help plz Quote
bri189a Posted July 21, 2005 Posted July 21, 2005 Maybe the file is open by another process? And I don't see anywhere that you close your XmlTextReader object, and you should be closing that your your other object that you're closing in a finally block too (along with any Dispose methods), that way it's not left open by the ASP.NET worker process if there is an error. If you've checked the permissions on the C:\Temp folder, and you are impersonating, and you've addressed the things I've mentioned as not being an issue, then there is something else happening. Wish I could be of more help. Oh and what is this line about...it does nothing: loc.Replace(@"\",@"\\"); Now if you had loc = loc.Replace(@"\", @"\\"); that would do something. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.