Post: VB.NET Programming Tutorial - AUTO UPDATER
03-10-2013, 01:52 PM #1
Specter
Pro Memer
(adsbygoogle = window.adsbygoogle || []).push({}); *** THIS WILL ONLY WORK IF THE USER IS CONNECTED TO THE INTERNET ***

Introduction:

Hey guys, I've decided to roll out some VB.NET tutorial's. I have been working with vb.net for a couple of years, and kept it all pretty closed. Now I'm going to be releasing some tutorial's in this section. I haven't seen any other threads on how to do this, so I am posting this thread.

Tutorial: #1 - Adding an auto-updater at program start

Required materials:

~ VB 2008 or 2010
~ Notepad :P
~ A hosting site (000webhost is a good one)

Video:

[Video is coming this week]




How to do it:

First, you're going to create a new WindowsFormApplication, OR open a project that is a WindowsFormApplication
You must login or register to view this content.

Now, you can customize your form and add the windows title and stuff, but for the sake of the tutorial I am going to assume you already know how to do this.

Now you should see a form similar to this on your screen
You must login or register to view this content.

Double click on that form, and it will bring you to the code editor
You must login or register to view this content.

Here is where the coding begins. Now what we are going to do, is make it so when the program is initiated, it checks an external XML file to see if there is an update available. If the number it checks is the same, it will say the program is up to date. If it is different, it will ask you if you want to update with a "yes" or "no" dialog. If the user clicks yes, it will automatically take them to the update download link in their default browser, or you can set it in a form browser. I will show you how to do both.

Before we do anything, we MUST import system.xml, or the code will give you errors. At the top of the code, before Public Class
Form1, we will put this code:
    Imports System.Xml

You must login or register to view this content.

Now that that is done, we will create a Private Function to check the XML file. We will call the private function "getXMLvalue" to make the code organised. Please note you will need to setup the site and upload the xml file. Once that is done, copy that link in there. I will show you how to do this in the end.
You must login or register to view this content.

Here is the code for the private function:
    Private Function getXMLValue(ByVal update As String, ByVal setting As String) As String
Dim xmlr As XmlReader = XmlReader.Create("https://yoursitehere.web44.net/xml/xml.xml")
xmlr.Read()
xmlr.ReadToFollowing(setting)

Dim value As String = xmlr.ReadString()
xmlr.Close()

Return value
End Function


Now we have our private function. Now we are going to call this in Form1_Load section. We are going to use IF statements, as its the easiest way to go. In this example, I show you how to do it with a webbrowser control, which can be easily added to the form.
You must login or register to view this content.

Here is the code:
    If getXMLValue(TextBox1.Text, "latestVersion") = "1.0.0.6" Then 'Change 2.7.0.0 to the assembly version of your app'
MsgBox("Latest Update 1.5 found installed. The software is up to date", MsgBoxStyle.Information, "You are up to date.")
Return
Else
If MessageBox.Show("Update found! Would you like to download?", "Update Found...", MessageBoxButtons.YesNo) = DialogResult.Yes Then
WebBrowser1.Navigate(TextBox2.Text)
MsgBox("Switch to the Update Tab to go to download page Winky Winky")
End If
End If
Return


In the code it brings up a message after stating go to the update tab to download. I suggest you put the webbrowser in a separate tab, because you still have full room for whatever your program is in the first tab. To do this, use a tab control. Also make textbox1 and textbox2's visible property to "false". This is so the users cannot see the textboxes/edit them.
You must login or register to view this content.

To edit the tab names, go to TabPageCollection in the TabControl1 properties and click the "..." button.
You must login or register to view this content.

Now when the user clicks "yes", the web browser in the "update" tab will automatically go to the updated program's download. Now we are pretty much done with VB. Now we need to go to notepad to create our XML file to upload.




We are going to put this code in the XML file for your VB program to check.
You must login or register to view this content.

Here is the code:
    <?xml version="1.0" encoding="UTF-8"?>
<checkForUpdate>
<latestVersion>1.0.0.6</latestVersion>
</checkForUpdate>


** CHANGE 1.0.0.6 TO WHATEVER YOU LIKE, AS LONG AS ITS IN #.#.#.# FORM! **




Now comes the easier part. We are going to setup our external site to check. We will use 000webhost for this. Go to the 000webhost website, and create an account. Once you have done that, create a new site, and go to its CPanel.

Now we are going to go to the file manager
You must login or register to view this content.

When you go to the file manager, you should come up with a panel similar to this one:
You must login or register to view this content.

Go to Public_Html, and create 2 folders called "xml" and "update".

Double click on the xml folder, and click upload. This is where we are going to upload our xml file. A dialog will come up, just choose your file and upload (I'm not going to post a picture because its pretty self explanatory).

Now copy the xml link, and the update link into your vb code.




* YOU'RE DONE! *

Now whenever you release an update for the program, upload it as the SAME name in the vb program, in the update folder on the site. Over-ride it. Now, in the software when you release, say 1.0.0.8, in the software YOU WILL NEED TO CHANGE THIS TO 1.0.0.8:
You must login or register to view this content.

Also, make sure to change the 1.0.0.6 on the xml file in the site, so that the users program will automatically know the program's new version has been released.
Last edited by Specter ; 03-10-2013 at 02:30 PM.

The following 3 users say thank you to Specter for this useful post:

Complete Speed, Pichu, Shots.
03-17-2013, 02:14 PM #2
Sloth
Banned
Originally posted by NGU
*** THIS WILL ONLY WORK IF THE USER IS CONNECTED TO THE INTERNET ***

Introduction:

Hey guys, I've decided to roll out some VB.NET tutorial's. I have been working with vb.net for a couple of years, and kept it all pretty closed. Now I'm going to be releasing some tutorial's in this section. I haven't seen any other threads on how to do this, so I am posting this thread.

Tutorial: #1 - Adding an auto-updater at program start

Required materials:

~ VB 2008 or 2010
~ Notepad :P
~ A hosting site (000webhost is a good one)

Video:

[Video is coming this week]




How to do it:

First, you're going to create a new WindowsFormApplication, OR open a project that is a WindowsFormApplication
You must login or register to view this content.

Now, you can customize your form and add the windows title and stuff, but for the sake of the tutorial I am going to assume you already know how to do this.

Now you should see a form similar to this on your screen
You must login or register to view this content.

Double click on that form, and it will bring you to the code editor
You must login or register to view this content.

Here is where the coding begins. Now what we are going to do, is make it so when the program is initiated, it checks an external XML file to see if there is an update available. If the number it checks is the same, it will say the program is up to date. If it is different, it will ask you if you want to update with a "yes" or "no" dialog. If the user clicks yes, it will automatically take them to the update download link in their default browser, or you can set it in a form browser. I will show you how to do both.

Before we do anything, we MUST import system.xml, or the code will give you errors. At the top of the code, before Public Class
Form1, we will put this code:
    Imports System.Xml

You must login or register to view this content.

Now that that is done, we will create a Private Function to check the XML file. We will call the private function "getXMLvalue" to make the code organised. Please note you will need to setup the site and upload the xml file. Once that is done, copy that link in there. I will show you how to do this in the end.
You must login or register to view this content.

Here is the code for the private function:
    Private Function getXMLValue(ByVal update As String, ByVal setting As String) As String
Dim xmlr As XmlReader = XmlReader.Create("https://yoursitehere.web44.net/xml/xml.xml")
xmlr.Read()
xmlr.ReadToFollowing(setting)

Dim value As String = xmlr.ReadString()
xmlr.Close()

Return value
End Function


Now we have our private function. Now we are going to call this in Form1_Load section. We are going to use IF statements, as its the easiest way to go. In this example, I show you how to do it with a webbrowser control, which can be easily added to the form.
You must login or register to view this content.

Here is the code:
    If getXMLValue(TextBox1.Text, "latestVersion") = "1.0.0.6" Then 'Change 2.7.0.0 to the assembly version of your app'
MsgBox("Latest Update 1.5 found installed. The software is up to date", MsgBoxStyle.Information, "You are up to date.")
Return
Else
If MessageBox.Show("Update found! Would you like to download?", "Update Found...", MessageBoxButtons.YesNo) = DialogResult.Yes Then
WebBrowser1.Navigate(TextBox2.Text)
MsgBox("Switch to the Update Tab to go to download page Winky Winky")
End If
End If
Return


In the code it brings up a message after stating go to the update tab to download. I suggest you put the webbrowser in a separate tab, because you still have full room for whatever your program is in the first tab. To do this, use a tab control. Also make textbox1 and textbox2's visible property to "false". This is so the users cannot see the textboxes/edit them.
You must login or register to view this content.

To edit the tab names, go to TabPageCollection in the TabControl1 properties and click the "..." button.
You must login or register to view this content.

Now when the user clicks "yes", the web browser in the "update" tab will automatically go to the updated program's download. Now we are pretty much done with VB. Now we need to go to notepad to create our XML file to upload.




We are going to put this code in the XML file for your VB program to check.
You must login or register to view this content.

Here is the code:
    <?xml version="1.0" encoding="UTF-8"?>
<checkForUpdate>
<latestVersion>1.0.0.6</latestVersion>
</checkForUpdate>


** CHANGE 1.0.0.6 TO WHATEVER YOU LIKE, AS LONG AS ITS IN #.#.#.# FORM! **




Now comes the easier part. We are going to setup our external site to check. We will use 000webhost for this. Go to the 000webhost website, and create an account. Once you have done that, create a new site, and go to its CPanel.

Now we are going to go to the file manager
You must login or register to view this content.

When you go to the file manager, you should come up with a panel similar to this one:
You must login or register to view this content.

Go to Public_Html, and create 2 folders called "xml" and "update".

Double click on the xml folder, and click upload. This is where we are going to upload our xml file. A dialog will come up, just choose your file and upload (I'm not going to post a picture because its pretty self explanatory).

Now copy the xml link, and the update link into your vb code.




* YOU'RE DONE! *

Now whenever you release an update for the program, upload it as the SAME name in the vb program, in the update folder on the site. Over-ride it. Now, in the software when you release, say 1.0.0.8, in the software YOU WILL NEED TO CHANGE THIS TO 1.0.0.8:
You must login or register to view this content.

Also, make sure to change the 1.0.0.6 on the xml file in the site, so that the users program will automatically know the program's new version has been released.

This is quite good you should try and find a way to get it to update without the user knowing if you need help PM me.

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo