[TUT] How to make an XML updater for your program in VB2008
Credits To: DJEKL
First:
Create a New Vb2008 Project or open one.
Second:
Add 2 textboxes;
Add one Button(optional)
Third:
Double Click on the form so it brings up the coding.
Fourth:
Right at the top before: Public Class Form1(or whatever your form is named) Copy and Paste this:
Imports System.IO
Imports System.Xml
Imports System.Net
Fith:
under the form1_load or button1_Click
add this code:
Dim xml As New XmlDocument()
xml.Load("http://yoursitehere.com/update.xml")
Dim root As XmlElement = xml.DocumentElement
Dim nodes As XmlNodeList = root.SelectNodes("//checkForUpdate")
For Each node As XmlNode In nodes
TextBox2.Text = node("latestVersion").InnerText
Next
TextBox1.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
If TextBox1.Text <> TextBox2.Text Then
If MessageBox.Show("Update found! Would you like to download?", "Update Found", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Dim wc As New WebClient()
wc.DownloadFile("http://www.yoursitehere.com/YourNeweestApp.exe", "latestVersion.exe")
End If
Process.Start(Application.StartupPath & "\latestVersion.exe")
Application.[Exit]()
Else
MessageBox.Show("No updates found.", "No Updates")
End If
Sixth:
now time to create a new xml document:
Open NotePad and copy and paste this:
<?xml version="1.0" encoding="UTF-8"?>
<checkForUpdate>
<latestVersion>1.0.0.0</latestVersion>
</checkForUpdate>
Now after you have done that. you can change the latest version to whatever you want.
Next click save as and name it: update.xml
and click all files instead of .txt.
Seventh:
Now upload that xml document to any file hosting site.
Eighth:
This is what your final code for the project should look like:
Imports System.IO
Imports System.Xml
Imports System.Net
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xml As New XmlDocument()
xml.Load("http://www.yoursitehere.com/update.xml")
Dim root As XmlElement = xml.DocumentElement
Dim nodes As XmlNodeList = root.SelectNodes("//checkForUpdate")
For Each node As XmlNode In nodes
TextBox2.Text = node("latestVersion").InnerText
Next
TextBox1.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
If TextBox1.Text <> TextBox2.Text Then
If MessageBox.Show("Update found! Would you like to download?", "Update Found", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Dim wc As New WebClient()
wc.DownloadFile("http://www.yoursitehere.com/YourNeweestApp.exe", "latestVersion.exe")
End If
Process.Start(Application.StartupPath & "\latestVersion.exe")
Application.[Exit]()
Else
MessageBox.Show("No updates found.", "No Updates")
End If
End Sub
End Class
Credits To: DJEKL
First:
Create a New Vb2008 Project or open one.
Second:
Add 2 textboxes;
Add one Button(optional)
Third:
Double Click on the form so it brings up the coding.
Fourth:
Right at the top before: Public Class Form1(or whatever your form is named) Copy and Paste this:
Imports System.IO
Imports System.Xml
Imports System.Net
Fith:
under the form1_load or button1_Click
add this code:
Dim xml As New XmlDocument()
xml.Load("http://yoursitehere.com/update.xml")
Dim root As XmlElement = xml.DocumentElement
Dim nodes As XmlNodeList = root.SelectNodes("//checkForUpdate")
For Each node As XmlNode In nodes
TextBox2.Text = node("latestVersion").InnerText
Next
TextBox1.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
If TextBox1.Text <> TextBox2.Text Then
If MessageBox.Show("Update found! Would you like to download?", "Update Found", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Dim wc As New WebClient()
wc.DownloadFile("http://www.yoursitehere.com/YourNeweestApp.exe", "latestVersion.exe")
End If
Process.Start(Application.StartupPath & "\latestVersion.exe")
Application.[Exit]()
Else
MessageBox.Show("No updates found.", "No Updates")
End If
Sixth:
now time to create a new xml document:
Open NotePad and copy and paste this:
<?xml version="1.0" encoding="UTF-8"?>
<checkForUpdate>
<latestVersion>1.0.0.0</latestVersion>
</checkForUpdate>
Now after you have done that. you can change the latest version to whatever you want.
Next click save as and name it: update.xml
and click all files instead of .txt.
Seventh:
Now upload that xml document to any file hosting site.
Eighth:
This is what your final code for the project should look like:
Imports System.IO
Imports System.Xml
Imports System.Net
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xml As New XmlDocument()
xml.Load("http://www.yoursitehere.com/update.xml")
Dim root As XmlElement = xml.DocumentElement
Dim nodes As XmlNodeList = root.SelectNodes("//checkForUpdate")
For Each node As XmlNode In nodes
TextBox2.Text = node("latestVersion").InnerText
Next
TextBox1.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
If TextBox1.Text <> TextBox2.Text Then
If MessageBox.Show("Update found! Would you like to download?", "Update Found", MessageBoxButtons.YesNo) = DialogResult.Yes Then
Dim wc As New WebClient()
wc.DownloadFile("http://www.yoursitehere.com/YourNeweestApp.exe", "latestVersion.exe")
End If
Process.Start(Application.StartupPath & "\latestVersion.exe")
Application.[Exit]()
Else
MessageBox.Show("No updates found.", "No Updates")
End If
End Sub
End Class