How to dispose or close an instance of XML Document in ASP.NET
-
There's a problem, wherein a XML Document.Save is resulting in the error the process cannot access the file, because it is being used by another process or the statement an Invalid XML Document.I think it's because I do not dispose the XML Document object after it's operation is complete.Is it possible to do this.Is there a workaround?
-
Answer:
It depends on which overload of the http://msdn.microsoft.com/en-us/library/system.xml.xmldocument.save.aspx method you are using. If you pass directly a filename as string there shouldn't be issues. If you pass a stream or xmlwriter you need to ensure that it is properly disposed: using (Stream stream = ...) { doc.Save(stream); }
gizgok at Stack Overflow Visit the source
Other answers
XmlDocument, as well as the newer XDocument, are in-memory representations of an XML document, so you don't need to close them. Perhaps you are using an underlying Stream or similar to read the documents, and that is what needs to be closed ? Without more context, it is almost impossible to answer.
driis
Related Q & A:
- How can I allow user to create posts in website using ASP.NET?Best solution by Programmers
- How to Undo previous action in asp.net?Best solution by forums.asp.net
- How to Search using jQuery ASP.Net?Best solution by Stack Overflow
- How to Play Audio files in ASP.NET?Best solution by Stack Overflow
- How to save high resolution image canvas to server using asp.net?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.