Replace existing xml file based on version number within external xml

NJCI

Member
Joined
May 9, 2011
Messages
8
Programming Experience
Beginner
I have a program that reads and saves data with an xml file. Once it is released, there is a "Check for update" button that the user will click to see if there is a new version of the xml file. The file contains the version number, ex: <Root><Version><Current>0.0001</Current></Version></Root>
I need a way for the application to find the xml file that is updated on the server, check the version number, compare it to the xml within the application, and then replace that file with the new one if applicable.
My logic so far:
' Public Variable As Single = "Version/Current" Read/Declare each time application runs
' Increment Variable each time file is saved
' When Check For Updates is clicked, connect to site and download xml. Create oldVersion variable and read xml for version.
' Declare newVersion variable. If newVersion > oldVersion Then: replace old file with downloaded file.

I am searching, but I need this done soon, so any help is GREATLY appreciated!
 
Dim local = "some.xml"
Dim remote = "http://server.net/some.xml"
Dim verLocal = XDocument.Load(local)...<Current>.Value
Dim verRemote = XDocument.Load(remote)...<Current>.Value
If verLocal <> verRemote Then
    My.Computer.Network.DownloadFile(remote, local)
End If
 
Thanks, that is working so far. This raises something I forgot about in the original post: is there a way to designate where the file is downloaded to? I want to be able to save it in the temp file probably (just so the application can check the version number), and then delete it once the user file is replaced.

Thanks again.
 
I want to be able to save it in the temp file probably (just so the application can check the version number), and then delete it once the user file is replaced.
That is not necessary as the code shows. Actually the code sample unintentionally included duplicate download of the remote document, the DownloadFile call can be replaced by simply saving the already downloaded remote document, eg:
Dim local = "some.xml"
Dim remote = "http://server.net/some.xml"
Dim verLocal = XDocument.Load(local)...<Current>.Value
Dim doc = XDocument.Load(remote)
Dim verRemote = doc...<Current>.Value
If verLocal <> verRemote Then
    doc.Save(local)
End If
 
Back
Top