View Full Version : Problem with Writing to XML File in VB.NET

08-18-2012, 07:11 PM
I have two VB.NET programs on different machines that need to read/write a shared XML file. The file is located in a shared folder on the network. First Program1 reads the XML file using XMLDocument and an IO stream. It processes it and then closes the stream. Program1 looks like this:

Dim doc As New Xml.XmlDocument
Dim stream As New IO.StreamReader("\\\Data\main.xml")

' ...... gets some data from xml here


Program2 creates some nodes in XMLDocument and saves it to the same shared file. It looks like this:

Dim doc As New Xml.XmlDocument

'.... creates some data on XML document here


And the problem: I run Program1 first and after some seconds, Program2. But when the second program attempts to write to the xml file I get an exception like this:
Can not access the file "\\\Data\main.xml" because it is being used by another process.
It's confusing, because I close the file in Program1 and also Program2 writes to it after some seconds (I'm sure the Stream.Close() is executed).
First program is runned on a Windows 7 64-bit machine and the second on a Windows XP machine. I'm using Visual Studio 2005 with .NET Framework 2.
Please help! Thanks.