如何在ASP.NET中处置或关闭XML文档的实例 [英] How to dispose or close an instance of XML Document in ASP.NET

查看:95
本文介绍了如何在ASP.NET中处置或关闭XML文档的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个问题,其中XML Document.Save导致错误,导致该进程无法访问该文件,因为该文件正在被另一个进程或无效XML文档的语句使用.我认为这是因为我没有处置该文件.操作完成后的XML Document对象.是否可以这样做.是否有解决方法?

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?

推荐答案

这取决于

It depends on which overload of the Save 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);
}

这篇关于如何在ASP.NET中处置或关闭XML文档的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆