ASP.NET process locks XML file, how to release/close it?

E

Edward

1. I have an .aspx file which parses an XML and XSL file out to
Response.Output.
2. However, after I run it once, the XML file is "locked" and I can't
open it until I end the ASP.NET process.
3. What else do I have to do beside closing FileStream, StreamReader
and XmlTextReader in my finally statement like this:

FileStream fs = null;
StreamReader reader = null;;
XmlTextReader xmlReader = null;

try {
fs = new FileStream(xmlPath, FileMode.Open, FileAccess.Read);
reader = new StreamReader(fs,Encoding.UTF7);
xmlReader = new XmlTextReader(reader);
XPathDocument doc = new XPathDocument(xmlReader);

XslTransform xslDoc = new XslTransform();
xslDoc.Load(xslPath);



xslDoc.Transform(doc,args,Response.Output);
}
catch (Exception e){
Response.Write("<textarea rows=\"10\" cols=\"80\"
style=\"font-family:arial;font-size:.8em\">Parse Error:\n\n " +
e.ToString() + "</textarea>");
}
finally {
fs.Close();
reader.Close();
xmlReader.Close();
}

Thanks,
Edward Tanguay
www.tanguay.info
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top