Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 6th, 2007, 07:25 PM
SirPoonga
Guest
 
Posts: n/a
Default Closing a file with XmlDocument?

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?

  #2  
Old March 6th, 2007, 11:05 PM
John Saunders
Guest
 
Posts: n/a
Default Re: Closing a file with XmlDocument?

"SirPoonga" <kevin.jonas@gmail.comwrote in message
news:1173208649.922129.8430@8g2000cwh.googlegroups .com...
Quote:
>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


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles