473,830 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2690
"SirPoonga" <ke*********@gm ail.comwrote in message
news:11******** ************@8g 2000cwh.googleg roups.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.Creat e(tw))
{
doc.WriteTo(wri ter);
}
}

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
6170
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 insert in the front. My code is give below. Is it possible to do without using XMLDOcument? Dim masterDoc As String = Request.PhysicalApplicationPath & "PageViews.xml" Dim writer As XmlTextWriter = Nothing
8
5789
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 suffices to open the XML file for read-only access. Once I have processed these values, I might need to update a bunch of subelements of a certain element. For example, I may need to update the Field Name attribute plus the DataField element value...
6
7523
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 call file.close or do I not need to??
6
1926
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 ( > 10MB) and I only need a certain node...I use an XmlTextReader to find the node I need, and then attempt to abort reading in the rest of the xml, but when I close the XmlTextReader I get the exception. I've included some sample code and xml that...
8
10479
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 on closing my stream, and I can't convince it not to. A much-simplified example is below; basically, as soon as the writer is disposed (marked **** below) the base stream gets closed - which is a pain if I was still using it ;-p The base...
1
2782
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 case and the closing tag removed in the second case. As a side note, if I change <inputto <input1>, the closing tag does not get removed.
2
1483
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
3161
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 somebody, please, help me out? I am on this for days. My code is as follows:
4
11179
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 see <CardNo></CardNothan <CardNo />). Is there a simple way to tell the XMLDocument to use the "traditional" way of showing an empty tag instead of always saving self-closing tags?
0
9780
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10769
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10520
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10196
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5775
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3070
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.