logo logo

The next-generation blog, news, and magazine theme for you to start sharing your stories today!

The Blogzine

Save on Premium Membership

Get the insights report trusted by experts around the globe. Become a Member Today!

View pricing plans

New York, USA (HQ)

750 Sing Sing Rd, Horseheads, NY, 14845

Call: 469-537-2410 (Toll-free)

hello@blogzine.com
.Net

[VB.Net] Auto Update Tutorial for VB.Net 2014

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 <center> Private page to chec…

avatar
Hung.Pro.VN

Developer Windows


  • 20/04/2016
  • Views

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

<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
Imports System.Text.RegularExpressions

Step 3

Add these

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

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

Related post


avatar

Hung.Pro.VN

Nhà thiết kế Web
View Articles

Tôi là admin trang Hung.Pro.VN là một người có đam mê với Blogspot, kinh nghiệm 5 năm thiết kế ra hàng trăm mẫu Template blogpsot như" Bán hàng, bất động sản, landing page, tin tức...

Nhận xét

Share this article