HighTechTalks DotNet Forums  

"In Use" exception on XMLDocument.Save

Dotnet XML microsoft.public.dotnet.xml


Discuss "In Use" exception on XMLDocument.Save in the Dotnet XML forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Terry
 
Posts: n/a

Default "In Use" exception on XMLDocument.Save - 02-20-2006 , 03:24 PM






When using XMLDocument.Save(strFileName) in .NET 2005, is there a way to
check (or trap) and see if the file is in use by another. I am using VB.NET.
Currently it just bombs and says the filename is in use by another. I want
to check or trap for this rather than blow-up. I tried using a Try...Catch,
but it bombs deep in the DOM, where I don't have control of it.

Here is the Code

Me.XMLDocument.Save(strFileName)


Reply With Quote
  #2  
Old   
Martin Honnen
 
Posts: n/a

Default Re: "In Use" exception on XMLDocument.Save - 02-21-2006 , 06:25 AM








Terry wrote:


Quote:
I tried using a Try...Catch,
but it bombs deep in the DOM, where I don't have control of it.

Here is the Code

Me.XMLDocument.Save(strFileName)
If the Save method calls some internal other methods that throw an
exception then nevertheless try/catch around the Save call should allow
you to catch the exception.

You can also pass other arguments to Save than simply a string with a
file name, you can pass in a Stream for instance and if you create that
yourself as needed (e.g. a FileStream where the constructor allows you
all control of FileMode, FileAccess, FileShare settings) then your code
has more control.



--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Reply With Quote
  #3  
Old   
Onawole, Clement Oladapo
 
Posts: n/a

Default Re: "In Use" exception on XMLDocument.Save - 02-21-2006 , 11:12 AM



Actually, if a file is in use, you may not be able to get a FileStream
object off it. I think a try/catch will do in this case.

"Martin Honnen" <mahotrash (AT) yahoo (DOT) de> wrote

Quote:

Terry wrote:


I tried using a Try...Catch, but it bombs deep in the DOM, where I don't
have control of it.

Here is the Code

Me.XMLDocument.Save(strFileName)

If the Save method calls some internal other methods that throw an
exception then nevertheless try/catch around the Save call should allow
you to catch the exception.

You can also pass other arguments to Save than simply a string with a file
name, you can pass in a Stream for instance and if you create that
yourself as needed (e.g. a FileStream where the constructor allows you all
control of FileMode, FileAccess, FileShare settings) then your code has
more control.



--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.