Needed:
1x a ProgressBar
2x a Label
start a new form:
Imports System.IO
Imports System.Net
Public Class Form1
Private WithEvents httpclient As WebClient
'Lets make the updater ready before we can start updating
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
httpclient = New WebClient
Try
Dim isAvailable As Boolean
isAvailable = My.Computer.Network.IsAvailable
If isAvailable Then
ProgressBar1.Value = 0
ProgressBar1.Maximum = 100
Label1.Text = "Demo updater is updating, please wait..."
'Add your own website and location of the file you want to update.
httpclient.DownloadFileAsync(New Uri("http://www.yoursite.com/test.exe.zip"), "test.exe.zip")
Else
MsgBox("There is no internet connection available.")
Application.Exit()
End If
Catch ex As Exception
MsgBox("Seems i can't run the update, Updater will exit now.")
Application.Exit()
End Try
End Sub
'Lets make the progressbar move same with the label2.
Private Sub OnDownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles httpclient.DownloadProgressChanged
ProgressBar1.Value = e.ProgressPercentage
'Make it more pro to show how much kb/mb we have downloaded so far.
Dim totalbytes As Long = e.TotalBytesToReceive / 1024
Dim mtotalbytes As Long = totalbytes / 1024
Dim bytes As Long = e.BytesReceived / 1024
Dim mbytes As Long = bytes / 1024
If totalbytes < 1 Then totalbytes = 1
If bytes < 1 Then bytes = 1
If totalbytes > 1024 Then
Label2.Text = mbytes.ToString & " MB of " & mtotalbytes.ToString & " MB"
Else
Label2.Text = bytes.ToString & " KB of " & totalbytes.ToString & " KB"
End If
End Sub
'Now we are ready to start the update
Private Sub OnFileDownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles httpclient.DownloadFileCompleted
If e.Cancelled Then
ElseIf Not e.Error Is Nothing Then
MsgBox("There was a problem downloading the update, please try again later.")
Application.Exit()
Else
'Lets see if the test.exe file or what ever you wanted to call it exist on the drive
'if so we gonna remove it first.
If My.Computer.FileSystem.FileExists(Application.StartupPath & "\test.exe") Then
My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\test.exe", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
End If
'After the dowload has finished we gonna rename the test.exe.zip to test.exe or what name you used.
If My.Computer.FileSystem.FileExists(Application.StartupPath & "\test.exe.zip") Then
My.Computer.FileSystem.RenameFile(Application.StartupPath & "\test.exe.zip", "test.exe")
End If
'Now the update has really been finsihed to lets try to run the test.exe at once before we exit the update.
If ProgressBar1.Value = 100 Then
Dim p As Process = New Process()
p.StartInfo.FileName = "test.exe"
p.Start()
Application.Exit()
End If
End If
End Sub
End Class
Hope you all like this tutorial.question let me know.
a other tutorial about a update will be coming soon because i gonna make something great of it :)
i3c
6 comments
Thanks for your grateful informations, this blogs will be really help for PHP tutorial.
Replyyw Abi :)
ReplyCan you help me, I am using the different coding but in it there is no progress bar so that I am unable to noticed the %completed for checking
ReplyBelow are the codes that I am using:
Try
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("Text link")
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim newestversion As String = sr.ReadToEnd
Dim currentversion As String = Application.ProductVersion
If newestversion.Contains(currentversion) Then
MsgBox("Application is up to date:" & vbNewLine & "Latest Version : --" & vbNewLine & "Current Version : --", MsgBoxStyle.Information, "Update Msg.")
Else
MsgBox("Update available," & vbNewLine & "Visit to our website to download newer version", MsgBoxStyle.Information, "Update msg")
End If
Catch ex As Exception
MsgBox("Error," & vbNewLine & "possible reasons:" & vbNewLine & "Check the internet connection." & vbNewLine & "internet speed may be slow so timed out error" & vbNewLine & "DM-Galaxy production may stopped the updates for this application.", MsgBoxStyle.Exclamation, "Error")
End Try
Bro you should try those things on your own , it's very easy please give it a try then only you will learn
ReplyVery Very Helpfull tutorial many thanks to you.. hope share more important tutorials like this.. helps very lot thanks.. :) bless you.
Replymy VB 2010 says Type Webclient is not defined
ReplyPost a Comment
Note: Only a member of this blog may post a comment.