How can I write to a single xml file from two programs at the same time?

Posted by Tom Bushell on Stack Overflow See other posts from Stack Overflow or by Tom Bushell
Published on 2010-06-10T16:44:52Z Indexed on 2010/06/10 16:52 UTC
Read the original article Hit count: 209

Filed under:
|
|

We recently started working with XML files, after many years of experience with the old INI files.

My coworker found some CodeProject sample code that uses System.Xml.XmlDocument.Save. We are getting exceptions when two programs try to write to the same file at the same time.

System.IO.IOException: The process cannot access the file 'C:\Test.xml' because it is being used by another process.

This seems obvious in hindsight, but we had not anticipated it because accessing INI files via the Win32 API does not have this limitation. I assume there's some arbitration done by the Win32 calls that work at a higher level than the the XmlDocument.Save method.

I'm hoping there are higher level XML routines somewhere in the .Net library that work similarily to the Win32 functions, but don't know where to start looking.

Or maybe we can set up our file access permissions to allow multiple programs to write to the same file?

Time is short (like almost all SW projects), and if we can't find a solution quickly, we'll have to hold our noses and go back to INI files.

© Stack Overflow or respective owner

Related posts about c#

Related posts about Xml