473,326 Members | 2,588 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,326 software developers and data experts.

Force a write

MAF
I am trying to save an XMLDocument and I occasionally get a sharing
violation. Can I force the write in this case?

System.Xml.XmlDocument XMLDoc = new System.Xml.XmlDocument();

//Load file

//Do something

XMLDoc.Save("c:\test.xml");
Nov 15 '05 #1
3 2015
MAF
Sorry my mistake I forgot to close the reader. This code fixed the problem

System.IO.FileStream fin ;

fin = new System.IO.FileStream(@XMLDataFile, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite) ;

XMLDoc.Load(new System.IO.StreamReader(fin)) ;

fin.Close();

"MAF" <mf*****@henwoodenergy.com> wrote in message
news:#j*************@TK2MSFTNGP09.phx.gbl...
I am trying to save an XMLDocument and I occasionally get a sharing
violation. Can I force the write in this case?

System.Xml.XmlDocument XMLDoc = new System.Xml.XmlDocument();

//Load file

//Do something

XMLDoc.Save("c:\test.xml");

Nov 15 '05 #2
MAF <mf*****@henwoodenergy.com> wrote:
Sorry my mistake I forgot to close the reader. This code fixed the problem

System.IO.FileStream fin ;

fin = new System.IO.FileStream(@XMLDataFile, System.IO.FileMode.Open,
System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite) ;

XMLDoc.Load(new System.IO.StreamReader(fin)) ;

fin.Close();


I would recommend using the using constructor for this:

using (FileStream fin = new FileStream (XMLDataFile,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite))
{
using (StreamReader reader = new StreamReader (fin))
{
XMLDoc.Load (reader);
}
}

While you don't *need* to close the reader, I generally think it's
better to dispose of everything that can be disposed.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Jon Skeet <sk***@pobox.com> wrote:
I would recommend using the using constructor for this:


<snip>

Sorry, that should have been "the using construct" not "the using
constructor". Darned muscle memory :(

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4

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

Similar topics

0
by: Jake | last post by:
How can I force an image download with IE using ASP.net?? Here is the catch: the image I want to force a write with is located on another web server. I can only reference the image with a URL. ...
6
by: Ray | last post by:
DB2 V7.2 Is it possible to list applications connected to a node by Auth ID? Is it possible to force applications connected to a node by Auth ID or am I forced to use App. Handle? Thanks, Ray
1
by: JezB | last post by:
I have a button which implicitly posts-back before firing the event that I have attached to that button. Within that event code I modify the controls collection on the page so I want to force...
2
by: Jon | last post by:
I have the following functionality in my program when someone clicks on a link, it brings up a page with an excel doc in it. I would however, like it to force the save file dialog all the time,...
8
by: Keith H | last post by:
I'm looking for a way to force the user to re-authenticate with their Windows username/password/domain after clicking the submit button on an ASP.NET page. This is for an internal application. ...
4
by: Richard Wilde | last post by:
How do I force an XML document to be downloaded from a web browser to a client? The XML document will come ideally from a dataset but if this is not possible then I can save off the XML document...
21
by: tradmusic.com | last post by:
Hi, We have the following in our stylesheet, which acts as a page header: #homepageheader { left: 0px; top: 0px; right: 0px; height: 183px; background-image:...
14
by: bonehead | last post by:
Greetings, I'm using the DoCmd.TransferText method to export the results of a MS Access query to a csv file. The csv will then be used to load an Oracle table. In other systems such as TOAD...
51
by: Hans | last post by:
Hi all, Is there a way that the program that created and started a thread also stops it. (My usage is a time-out). E.g. thread = threading.Thread(target=Loop.testLoop) thread.start() ...
2
by: cottonj | last post by:
is there anyway to force an event, like mouseover? I have a page that loads, and due to some complex js code (not mine) it fails to write labels to tabs until the user does a mouseover on the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.