c# xml.Load() locking file on disk causing errors

前端 未结 4 1789
醉梦人生
醉梦人生 2020-12-05 23:46

I have a simple class XmlFileHelper as follows:

public class XmlFileHelper
{
    #region Private Members

    private XmlDocument xmlDoc = new XmlDocument();         


        
4条回答
  •  余生分开走
    2020-12-06 00:32

    You can do this

    using (Stream s = File.OpenRead(xmlFilePath))
    {
        xmlDoc.Load(s);
    }
    

    instead of

    xmlDoc.Load(xmlFilePath);
    

提交回复
热议问题