473,383 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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?

Mar 6 '07 #1
1 2647
"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
Mar 6 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: reddy | last post by:
I am trying to insert a node into an XMLFile. using XMLTextwriter. My Question is Is it possible to do without using XMLDocument. Because its loading all the the file into memory. I just want to...
8
by: yinjennytam | last post by:
Hi all, I'm new to .NET and XML and I have a question. Given an XML file, I want to navigate its content and look for one or two particular elements to get their values. At this point, it...
6
by: Nick | last post by:
Hi, simple question XmlDocument doc = new XmlDocument(); FileStream file = new FileStream (PathAndFileName,FileMode.Open,FileAccess.Read,FileShare.ReadWrite); doc.Load(file); should I now...
6
by: Tim Barg | last post by:
I am using a CryptoStream to encrypt and then save an xml file. However, when reading it back in, I am getting a CryptographicException. I am hitting this because I have some large xml files ( >...
8
by: Marc Gravell | last post by:
I want to write a method that will accept a stream as a parameter, and which will write xml to the stream (based in reality on database results) using the XmlTextWriter class. However, this insists...
1
by: S. David Kyle | last post by:
I am having a weird issue when I generate an input Html tag from a Xsl transformation. When the trasform is executed on the xsl below, the <inputtag has the closing slash removed in the first...
2
by: TPK | last post by:
Is there any way javascript can be used to assemble a XML file? Any resources out there that may explain how to do this (if possible)? TPK
3
by: shapper | last post by:
Hello, Could someone tell me how to convert a XML file into another XML file using a XSL file with a parameter? I created the code to do it, and it seems ok, but it is not working. Could...
4
by: David Cartwright | last post by:
Hi, I have a VB.NET (VS2005, .NET 2.0) application producing an XML file which is then used by a third-party product. It turns out the latter doesn't like self-closing tags (i.e. it would rather...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.