Hello There, Guest!
View New Posts  |  View Today's Posts
[VB.Net] [Tutorial]Auto Update Tutorial for VB.Net

  • 0 Vote(s) - 0 Average


07-12-2012, 05:04 AM #1
Gemster
Junior Member
**
Posts: 41 Threads:9 Joined: Jul 2012 Reputation: 4

[Tutorial]Auto Update Tutorial for VB.Net
There are only 3 parts that needs changing and them parts are commented.


Ok first you need a webhost/website

Step 1

Make a webpage, call it UpdateCHK.html

Add this


PHP Code:
<center>
Private 
page to check my programs for updates.
<
br><br>

MyProgramName=v1.0=YOURDOMAINHERE/ProgramFileName.zip
<br><br>

</
center


Change this line to match yours "MyProgramName=v1.0=YOURDOMAINHERE/ProgramFileName.zip" I use .zip but you can use .exe if you want.

Step 2

In VB make an import at the very top
Code:
Imports System.Text.RegularExpressions

Step 3

Add these
Code:
Dim CurrentVersion As String = "v1.0" '--- Change this to Current version, needs changing on every update
Dim ProgramName As String = "MyProgramName" '--- Change this to Your Progran Name
Dim SiteName As String = "YOURDOMAINHERE/UpdateCHK.html" '--- Change this to Your Update page
Dim VersionCHK, GetVer, GetVerLink As String
Dim GetUpd As Integer

There is only 3 things to change that are commented for you.

Step 4

Add this full Sub
Code:
Public Sub AutoUpdate()
Dim WebRequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(SiteName)        
Dim WebResponse As System.Net.HttpWebResponse = WebRequest.GetResponse        
Dim STR As System.IO.StreamReader = New System.IO.StreamReader(WebResponse.GetResponseStream())        
Dim ReadSource As String = STR.ReadToEnd        
Dim Regex As New System.Text.RegularExpressions.Regex(ProgramName & "=v(\d+).(\d+)=(.*?).zip")        
Dim matches As MatchCollection = Regex.Matches(ReadSource)

        For Each match As Match In matches            
Dim RegSplit() As String = Split(match.ToString, "=")            
GetVer = RegSplit(1)            
GetVerLink = RegSplit(2)      
Next

        If GetVer > CurrentVersion Then            
GetUpd = MsgBox(ProgramName & " is an old version." & vbCrLf & "New Update is available" & _          
vbCrLf & "Current version: " & CurrentVersion & vbCrLf & "Version Avalible: " & _            
GetVer & vbCrLf & vbCrLf & "Update Now?", vbYesNo, "Update")

            If GetUpd = vbYes Then              
Dim sfd As New SaveFileDialog                
sfd.FileName = IO.Path.GetFileName(GetVerLink)                
If sfd.ShowDialog = DialogResult.OK Then                    
My.Computer.Network.DownloadFile(GetVerLink, sfd.FileName)                
End If            
End If
        Else            
MsgBox(ProgramName & " is upto date." & vbCrLf & "Current version: " & CurrentVersion, 0, "Update")        
End If
    End Sub

And thats it, call "AutoUpdate()" on either a button click or form load

I know there is shorter ways to do this like using webbrowsers ect but this is my method and it works like a charm :D

Thanks and Enjoy
This post was last modified: 07-12-2012, 05:12 AM by Gemster.

07-12-2012, 07:51 AM #2
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: [Tutorial]Auto Update Tutorial for VB.Net
Looks nice and simple. There are many ways to complete the same task, but this way looks like it will get the job done. And, it's simple enough that even beginners can get a grasp of it. This will help them advance to even more complicated methods.

Thanks!

07-12-2012, 10:23 AM #3
Gemster
Junior Member
**
Posts: 41 Threads:9 Joined: Jul 2012 Reputation: 4

RE: [Tutorial]Auto Update Tutorial for VB.Net
Yes there are a lot of methods out there and by complicated im guessing the use of mysql ?

For simple tasks like auto updateing then this is very useful and fast since it uses webrequests.

Thanks

07-12-2012, 10:39 AM #4
KoBE
¯\_(ツ)_/¯
******
Global Moderators
Posts: 4,862 Threads:494 Joined: Jun 2011 Reputation: 67

RE: [Tutorial]Auto Update Tutorial for VB.Net

07-12-2012, 11:01 AM #5
Gemster
Junior Member
**
Posts: 41 Threads:9 Joined: Jul 2012 Reputation: 4

RE: [Tutorial]Auto Update Tutorial for VB.Net
Ok making it more complicated would be using a prograssbar ect but thats just added to the UI and the code for the update part remains the same.

The first link OMG why add 3-4 classes to accomplish something that can be really simple, I do like it tho. The second link i can not see the code as its been removed from pastebin.

Thanks

07-12-2012, 12:03 PM #6
sh@rp
Member
**
Posts: 199 Threads:11 Joined: Feb 2012 Reputation: 10

RE: [Tutorial]Auto Update Tutorial for VB.Net
(07-12-2012, 11:01 AM)Gemster Wrote:  The first link OMG why add 3-4 classes to accomplish something that can be really simple, I do like it tho....

lool ... Because when you develop applications in object language, I consider it perfectly legitimate to structure a program like this. This is not your opinion clearly ...

Anyway I notice that you have no exception handling in your code snippet.o_O" You add lines one after the other I think it is as "unfinalized" job. However your approach with your html page is interesting, except I'd rather use an xml file to do that trick.
In addition to use a URL without testing the user's Internet connection is a terrible mistake....

Shp. Wink2
This post was last modified: 07-12-2012, 12:09 PM by sh@rp.

07-12-2012, 12:42 PM #7
Gemster
Junior Member
**
Posts: 41 Threads:9 Joined: Jul 2012 Reputation: 4

RE: [Tutorial]Auto Update Tutorial for VB.Net
(07-12-2012, 12:03 PM)sh@rp Wrote:  
(07-12-2012, 11:01 AM)Gemster Wrote:  The first link OMG why add 3-4 classes to accomplish something that can be really simple, I do like it tho....

lool ... Because when you develop applications in object language, I consider it perfectly legitimate to structure a program like this. This is not your opinion clearly ...

Anyway I notice that you have no exception handling in your code snippet.o_O" You add lines one after the other I think it is as "unfinalized" job. However your approach with your html page is interesting, except I'd rather use an xml file to do that trick.
In addition to use a URL without testing the user's Internet connection is a terrible mistake....

Shp. Wink2
This is only a sub for an updater and when added into a project the coder would add the internet check with a progressbar on form_load or whatever.

For adding the lines one after another i had problems posting this with formatting until i learned about the source editor part of it.

Again this is only an auto update check sub, nothing more. Its ment to be simple but fast.

Thanks

02-05-2014, 06:05 PM #8
userspassw0rd
Junior Member
**
Posts: 9 Threads:1 Joined: Feb 2014 Reputation: 0

RE: [Tutorial]Auto Update Tutorial for VB.Net
Simple Code Nicethread Both Thumbs Up

02-08-2014, 04:34 AM #9
assasaha
Junior Member
**
Posts: 2 Threads:0 Joined: Jul 2013 Reputation: 0

RE: [Tutorial]Auto Update Tutorial for VB.Net
Nice Ide Thanks,,, brother,,,, :)




Forum Jump:


Possibly Related Threads...
Thread Author Replies Views Last Post
  Any Facebook c# sdk tutorial? ѕα3єкα 3 1,649 12-13-2015, 02:42 AM
Last Post: AceInfinity
  Lync 2010 Auto Responder KoBE 1 1,696 06-08-2015, 10:49 AM
Last Post: KoBE
   Screenshot Utility with Auto Upload KoBE 12 7,385 08-28-2014, 08:12 PM
Last Post: KoBE
   DateTimePicker Auto Update? Lee Stevens 4 2,744 01-17-2014, 10:58 AM
Last Post: Miklo
   Update Form from Class Thread Lee Stevens 2 2,410 10-13-2013, 05:50 PM
Last Post: Lee Stevens


Users browsing this thread: 1 Guest(s)