Coludn't acces the XML file in Visual Studio c#

本文关键字:in file Visual Studio XML the acces Coludn | 更新日期: 2023-09-27 18:34:31

执行下面的代码时,它在打开文件时显示错误它说文件字典.xml已经被某个进程使用

它在这里显示错误

FileStream fs = new FileStream("dict.xml", FileMode.Open, FileAccess.Read(;

  FileStream fs = new FileStream("dict.xml", FileMode.Open, FileAccess.Read);
  xmldoc.Load(fs);
  xmlnode = xmldoc.GetElementsByTagName("dict");
  for (i = 0; i <= xmlnode.Count - 1; i++)
  {
      w[i] = xmlnode[i].ChildNodes.Item(0).InnerText;
      m[i] = xmlnode[i].ChildNodes.Item(1).InnerText;
  }

Coludn't acces the XML file in Visual Studio c#

如果其他内容对文件有锁定,如果您指定 FileShare.ReadWrite,您应该仍然可以读取它:

using (FileStream fs = new System.IO.FileStream("dict.xml", FileMode.Open, FileAccess.Read, FileShare.ReadWrite) {