我正在创建一个应用程序,我正在读取xml,添加一些节点然后保存它。
保存时我收到以下错误:
“进程无法访问文件'C:\ p401573 \ myxml.xml',因为它 正在被另一个进程使用。“
我的代码如下:
Dim xmldoc As New XmlDocument
xmldoc.Load("C:\p401573\myxml.xml")
Dim nlist As XmlNodeList = xmldoc.GetElementsByTagName("UserSettings")
Dim elem As XmlElement = xmldoc.CreateElement("", "User", "")
elem.SetAttribute("Name", txtName.Text)
elem.SetAttribute("Rights", "N")
nlist.Item(0).AppendChild(elem)
xmldoc.Save("C:\p401573\myxml.xml")
在我将XML文档保存回文件上面的最后一行代码时出现错误。有时这段代码正在运作
myxml.xml文件
<?xml version="1.0" encoding="utf-8"?>
<UserSettings>
<User Name="vijavaib" SSOId="45699795" group="New Business" Rights="" />
<User Name="girinity" SSOId="757888" group="PHS" Rights="" />
<User Name="bandalpa" SSOId="64567788" group="LICENSING" Rights="" />
<User Name="hjdhjj" SSOId="658885858" group="PHS" Rights="" />
<User Name="vvv" SSOId="3165667" group="PHS" Rights="" />
<User Name="cxvbbb" SSOId="5614367" group="PHS" Rights="" />
<User Name="cxvbbb" SSOId="5614367" group="LICENSING" Rights="" />
<User Name="cxvbbb" SSOId="5614367" group="LTCNB" Rights="" />
<User Name="" SSOId="" group="ALL" Rights="" />
<User Name="gvbfgfd" SSOId="423556767" group="New Business" Rights="N" />
<User Name="tgytyry" SSOId="654657676" group="New Business" Rights="N" />
<User Name="yuuyuut" SSOId="546546757" group="New Business" Rights="N" />
<User Name="fhgffgjfj" SSOId="576575565" group="New Business" Rights="N" />
<User Name="hjhjghdj67658" SSOId="654776787" group="New Business" Rights="N" />
<User Name="hyjhjhgj" SSOId="677887789" group="New Business" Rights="N" />
<User Name="ttioioiuo" SSOId="787589980" group="ALL" Rights="N" />
</UserSettings>
但有时会出错。