How to modify by loading and saving the same xml file
Posted
by
cynthia hong
on Stack Overflow
See other posts from Stack Overflow
or by cynthia hong
Published on 2011-11-22T09:07:54Z
Indexed on
2011/11/22
9:51 UTC
Read the original article
Hit count: 417
I have a problem with modifying xml file when i first load and then save it with same file path and name. Below is my code. The error is "Access to the path C:\MyApp\Web.config is denied. If i change the path of the xdoc.Save to be different from xdoc.Load, then it will be ok. What is your recommandation to solve this problem? If possible, i need to modify the existing xml file(meaning xml file for loading and saving is the same path).
XmlDocument xdoc = new XmlDocument();
xdoc.Load(@"C:\\MyApp\\Web.config");
XmlNode xn = xdoc.SelectSingleNode("//configuration/MyProvider");
XmlElement el = (XmlElement)xn;
el.SetAttribute("defaultProvider", "MyCustomValue");
xdoc.Save(@"C:\\MyApp\\Web.config");
Thanks in advance.
© Stack Overflow or respective owner