Hi,
I have written a code to update the contents of an existing xml file.
For updating I open the file using Load method as given below:
Xdoc.Load("Test1.xml");
After updating the contents when i save the file using "Save" function as given below:
Xdoc.Save("Test1.xml);
I get following exception:
"The process cannot access the file 'C:\BartechPasswords.xml' because it is being used by another process."
Do we need to firt close the file or unload the file. Please reply the post as soon as possible.
Thanks in advance.

Ryan AlfordRank #1,411 · 1.2K reputationPosted Jul 16, 2008, 9:53 AM EDT
my code works just fine:
XmlDocument xdoc = new XmlDocument();
xdoc.Load(m_settingsPath);
XmlNode root = xdoc.DocumentElement;
XmlNode xNode;
xNode = root.SelectSingleNode("/configuration/Main.ConnectionString");
xNode.InnerText = Crypto.Encrypt(m_connectionString.ConnectionString, Globals.CryptoOffset);
xdoc.Save(m_settingsPath);
Bechir BejaouiRank #144 · 15.9K reputationPosted Jul 16, 2008, 1:28 PM EDT
http://dotnetuniver.blogspot.com/
Pravara Patil37 reputationPosted Jul 16, 2008, 8:43 PM EDT
My code is as given below:
Xdoc.Load(strFilePath);
XmlNode Node = Xdoc.SelectSingleNode("PasswordSeries"); foreach (XmlNode nd in Node){
if (nd.Name == "PasswordGenerationDate"){
XmlNode xNode = nd.Attributes.GetNamedItem("StartIndex");xNode.Value = val;
}
}
Xdoc.Save(strFilePath);
Mahesh ChandRank #1 · 393.3K reputationPosted Jul 17, 2008, 5:04 AM EDT
Here is a complete chapter on XML programming in C#:
XML Programming in C# and .NET
Pravara Patil37 reputationPosted Jul 17, 2008, 5:46 AM EDT
Thanks all of you.
The problem is solved. It was my mistake. I am having another method to read the same file, in that method i forgot to close the file opened using XMLTextReader.
Now everything is working.
Thanks once again.
Ryan AlfordRank #1,411 · 1.2K reputationPosted Jul 17, 2008, 6:22 AM EDT
Pravara Patil37 reputationPosted Jul 17, 2008, 6:27 AM EDT
Thanks for your valueable suggestion.
Actually i am working with XML files for the first time. So, i don't have much idea.
(Please don't mind one silly question:) Will the code work even if we have multiple nodes in the xml file.
Ryan AlfordRank #1,411 · 1.2K reputationPosted Jul 17, 2008, 7:26 AM EDT
XmlNode Node = Xdoc.SelectSingleNode("PasswordSeries");
it is only returning one XmlNode(notice the SingleNode in the method name). Using this method, it doesn't matter how many nodes you have since you are only looking at one of them.