简体   繁体   中英

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

When executing the code below it shows an error at opening the file it says the file dict.xml is already in use by some process

It shows error here

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;
  }

如果指定了FileShare.ReadWrite,则如果文件有其他锁定,您仍然应该能够读取它:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM