写入现有xml文件时出错 [英] Error while writing into an existing xml file

查看:96
本文介绍了写入现有xml文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在创建一个应用程序,我正在读取xml,添加一些节点然后保存它。



保存时我收到以下错误。



进程无法访问文件'C:\p401573 \ myxml.xml '因为它正在被另一个进程使用。



我的代码如下

Hi,

I am creating an application where i am reading an xml,Adding some nodes and then saving it.

While saving i am getting following error.

"The process cannot access the file '"C:\p401573\myxml.xml"' because it is being used by another process."

My code is as follows

Dim xmldoc As New XmlDocument
xmldoc.Load("C:\p401573\myxml.xml")
'ConfigurationManager.AppSettings("Path") + "
Dim nlist As XmlNodeList = xmldoc.GetElementsByTagName("UserSettings")
Dim elem As XmlElement = xmldoc.CreateElement("", "User", "")
elem.SetAttribute("group", cbxUserProfile.SelectedItem)
elem.SetAttribute("Rights", "N")
nlist.Item(0).AppendChild(elem)
xmldoc.Save("C:\p401573\myxml.xml")





在最后一行代码中,当我将xml文档保存回上面的文件时出现错误。有时这段代码正在工作



myxml.xml文件代码



On last line of code when i am saving xml document back to the file above error comes.Some times this piece of code is working

myxml.xml file code

<?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>







但有时会出错。



请帮忙急。




But some times it give error.

Please Help its urgent.

推荐答案

完成它!

进程无法访问该文件,因为它正被另一个进程使用


这篇关于写入现有xml文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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