Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 8th, 2008, 04:02 AM
Registered User
Join Date: May 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Update xml file simultaneously from two .net app

Hello everyone,

I have an issue in working with xml files. i want to change the contents of an xml from two applications simultaneously.
this is my xml document
<?xml version="1.0" encoding="Windows-1252"?>

currently i have the code for update the contents
Dim XMLDom As New XmlDocument()
'//load your xml file
Dim newXMLNodes As XmlNodeList = XMLDom.SelectNodes("/OrderList/Order/Orderno")

For Each newXMLNode1 As XmlNode In newXMLNodes
If newXMLNode1.InnerText = "31" Then
newXMLNode1.InnerText = "AS31"
End If


XMLDom = Nothing

its main problem is that i load the full document to XMLDom and finaly i overwrite the existing xml document,so i lost the data from the second application .
Can anyone please help me with this

Old May 9th, 2008, 08:33 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

You need to provide some locking mechanism on the file.

The core of this problem is with the way that XmlDocument works. When you load it, it reads the whole XML file into object memory and releases the file. So another instance of the program can do the same and neither will know about the other. I haven't done this type of work but I imagine there is some way to lock the file using the System.IO.File class. You can load an XmlDocument from a file stream. So you could manually open the file using the File class methods to obtain a file stream with a lock on the file, then fill your XmlDocument from it, keeping the file open. This will provide the lock at the file system level so another program instance can't write to it until you release it. The other program could be forced to wait to provide read-only access to the file.


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to update a xml file billbillbill XML 2 April 11th, 2007 08:23 AM
post xml data from ASP.NET app to ASP app polekat Classic ASP Professional 2 January 31st, 2007 08:44 AM
update xml file using vbs thesun99 XML 0 March 21st, 2005 02:32 AM
Getting VB.NET to load & update XML file kyma XML 0 March 19th, 2005 04:58 PM
Multiple file download Simultaneously goodybuddy General .NET 1 January 24th, 2005 10:17 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.