[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 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

Hướng dẫn bình luận

Mọi người để lại bình luận góp ý, nhận xét về những bài viết mà mình chia sẽ văn minh lịch sự hay kích động, Không spam, không chèn link quảng cáo, bán hàng, Không sử dụng từ ngữ thô tục, xúc phạm, kích động, Link chỉ được phép khi thực sự liên quan đến nội dung bài viết, Không mạo danh người khác hoặc sử dụng email giả, Bình luận vi phạm sẽ bị xóa không cần thông báo trước.
Mọi người lưu ý răng, nếu muốn chia sẽ code ở bình luần thì cần mã hóa code trước khi bỏ vào khung nhé. :)
⑴ Chèn ℂ𝕤𝕤 theo mẫu : [pre css] ℂ𝕤𝕤 [/pre]
⑵ Chèn ℍ𝕥𝕞𝕝 theo mẫu : [pre html] ℍ𝕥𝕞𝕝 [/pre]
⑶ Chèn 𝕁𝕒𝕧𝕒𝕤𝕔𝕣𝕚𝕡𝕥 theo mẫu : [pre js] 𝕁𝕒𝕧𝕒𝕤𝕔𝕣𝕚𝕡𝕥 [/pre]

🖼️ Chèn 𝕀𝕞𝕒𝕘𝕖 theo mẫu : [img] 𝕃𝕚𝕟𝕜 𝕀𝕞𝕒𝕘𝕖 [/img]
🎞️ Chèn Video 𝕐𝕠𝕦𝕥𝕦𝕓𝕖 theo mẫu : [youtube] 𝕃𝕚𝕟𝕜 𝕪𝕠𝕦𝕥𝕦𝕓𝕖 [/youtube]

Đăng nhận xét

@Bloggers Community

@Catalogics

CSS (31) Google (7)

@Total Pageviews