"SirPoonga" <ke*********@gmail.comwrote in message
news:11********************@8g2000cwh.googlegroups .com...
>I am storing some small amounts of data in an xml file using
XmlDocument. I basically do a .Load(filename), processing,
then .Save(filename). However, once and awhile on the .Load it will
say the file is in use by another process. This is the only program
to use that file. I am using C#. Any ideas on what is going on?
I've seen this from time to time. When I so, I start to explicitly use a
TextWriter and put it into a using() statement:
using (TextWriter tw = File.CreateText("path"))
{
XmlDocument doc = new XmlDocument();
using (XmlWriter writer = XmlWriter.Create(tw))
{
doc.WriteTo(writer);
}
}
If I get paranoid enough, I add tw.Flush(); before the final close bracket.
John