...

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



amirahmadian
08-18-2012, 07:11 PM
Hi.
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("\\192.168.1.2\Data\main.xml")
doc.Load(stream)

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

stream.Close()
stream.Dispose()

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

doc.Save("\\192.168.1.2\Data\main.xml")

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 "\\192.168.1.2\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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum