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 AlfordPosted Jul 17, 2008, 11:26 AM
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.
Pravara PatilPosted Jul 17, 2008, 10:27 AM
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 AlfordPosted Jul 17, 2008, 10:22 AM
Pravara PatilPosted Jul 17, 2008, 9:46 AM
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.
Mahesh ChandPosted Jul 17, 2008, 9:04 AM
Here is a complete chapter on XML programming in C#:
XML Programming in C# and .NET
Pravara PatilPosted Jul 17, 2008, 12:43 AM
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);
Bechir BejaouiPosted Jul 16, 2008, 5:28 PM
http://dotnetuniver.blogspot.com/
Ryan AlfordPosted Jul 16, 2008, 1:53 PM
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);