Vb.Net Tutorial - Update Checker

Status
Not open for further replies.
K

KamaluNg

Guest
Original poster
Vb.Net Tutorial - Update Checker
Difficulty: Medium

1. Before we get started we need to setup an online text file.

There are multiple hosting websites that can do this for you.
An often used one is Ripway: http://www.ripway.com/

Although i prefer 000webhost: http://www.000webhost.com/

Sign-Up at either of the websites or any web hosting website you desire.


2. Now create a text file and type in this:
Code:
1.0.0.0


3. Now upload the textfile to your webhost and copy the URL to the file.
Heres an example of the type link you'll need to get, i used 000webhost:
Code:
http://kcs1.webatu.com/yahoobot.html

As you can see if you view it the only text inside the document is 1.0.0.0

Note: For 000webhost, upload your files inside of the folder labeled Public. Click on "view" to show where your file is located.

5. Save this link. Its important. Time to do work. Open up Visual Basic.

6. First off, lets get set up. Create a new project and add the following:

1 Label
1 Button
1 Progress Bar
2 Timers

newbitmapimagegh.png


7. Alright so let me explain this quickly.
newbitmapimagene.png


The area called Assembly Information holds the version of your program. The code we are about to write will check your programs assembly information and check text in your online textfile. If they match then we'll have the program tell the user that no update is needed. If they don't match then we'll have the program tell the user that an update is required and/or recommended. To do this simply change the text in your online textfile to 1.0.0.1 or change any value. Its up to you. So lets code.

8. Double Click on your Button to view the code. First we need to start your timers, so type in.
Code:
timer1.start
timer2.start
However we won't be coding anything for timer1 just yet.

Double click on timer2. Right off the bat type in:
Code:
timer2.stop

This will stop the timer and only run through it once.

Now we need to get your program to check the text file online. To do this we'll be using httpwebrequest to get the text from your URL. Type in:
Code:
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("URL-HERE")
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())

Then we'll need to diminish some strings. To do this Type In:
Code:
Dim newestversion As String = sr.ReadToEnd()
Dim currentversion As String = Application.ProductVersion

Now hold that thought. Check to see if your caught up then lets do the coding for timer1 before continuing.
newbitmapimagegs.png


9. Double click on Timer1 and lets write that piece of coding really quickly.

We'll need to make the progress bar increase each time the timer clicks. so lets type in this:
Code:
ProgressBar1.Value += 10

Now we have to make sure it stops.... so type in:
Code:
If ProgressBar1.Value = 100 Then
Timer1.Stop()
timer2.start

Check to see if your caught up.
newbitmapimage2be.png


Thats all for timer1! Back to timer2!

10. From here all we have left is for your program to tell the user if an update is required or not and add a stop to your timer1.

Type in:
Code:
If progressbar1.value = 100 then
        If newestversion.Contains(currentversion) Then
            Label1.text = ("You currently have the newest version")
            timer1.stop
        Else
            Label1.Text = ("A newer Version Available")
            timer1.stop
        End If
End If

You should have this:
newbitmapimagems.png


Your Done! You have successfully made a Update Checker for your program.

I'll be making another tutorial on how to download and run a file soon then i'll link it here.

Any questions or comments? Feel free to post below.
 

Chaddith

Member
member
Joined
Jul 31, 2011
Posts
17
Reaction score
2
Points
0
@Greenoli, It automatically checks for updates, and if there is a new version, it displays it.

@OP, You should make it automatically download or at least prompt them asking if they want to download using DialogResults. Use System.Net and the DownloadFileAsync Client.
 
K

KamaluNg

Guest
Original poster
It adds a version checker to your program. So if you update your program people will know :D

I plan to do an entire tutorial about downloading and running files from your program as stated above.
 
Status
Not open for further replies.