So here you go:
I'm using files which I get when I build my Setup-project, so I think this is not working in Visual Studio Express-editions.
First things first, I made this as a class so I can use it in different projects, without rewriting it, with just a little modifications.
Class with functionality is named as Version.vb and it contains:
Version.vb
Imports System.IO
Imports System.Net
Imports System.Text
Class Web_update
Dim version As String
Public Shared Downuri As String
Public Shared Sub Main()
Dim URI As String
'
'REPLACE Program WITH YOUR APPLICATIONS NAME.
'
'REMEMBER TO EDIT FILEVERSION IN ASSEMBLY INFORMATION
'
'
'Edit URI to your version.html-file.
URI = "http://your.domain.com/Program_version.html"
'Edit URI to your programs zip-file
Downuri = "http://your.domain.com/Program.zip"
Dim wr As HttpWebRequest = CType(WebRequest.Create(URI.ToString), HttpWebRequest)
Dim ws As HttpWebResponse = CType(wr.GetResponse(), HttpWebResponse)
Dim str As Stream = ws.GetResponseStream()
Dim inBuf(100000) As Byte
Dim bytesToRead As Integer = CInt(inBuf.Length)
Dim bytesRead As Integer = 0
While bytesToRead > 0
Dim n As Integer = str.Read(inBuf, bytesRead, bytesToRead)
If n = 0 Then
Exit While
End If
bytesRead += n
bytesToRead -= n
End While
Dim fstr As New FileStream("version.txt", FileMode.OpenOrCreate, FileAccess.Write)
fstr.Write(inBuf, 0, bytesRead)
str.Close()
fstr.Close()
Dim sr As StreamReader = New System.IO.StreamReader("version.txt")
Dim version As Integer = CInt(sr.ReadToEnd.Replace(".", "").Substring(0, 4))
sr.Close()
If version > CInt(Application.ProductVersion.Replace(".", "")) Then
Dialog1.ShowDialog()
Else
MessageBox.Show("There is no new updates.", "Update", MessageBoxButtons.OK)
End If
End Sub 'Main
End Class 'Web_update
As you can see from the code below I have created checking in the dialog which contains 3 buttons.
One for downloading the zip-file from web, one for downloading and running the update, and Cancel button.
Dialog1.vb
'REPLACE Program WITH YOUR APPLICATIONS NAME.
Imports System.Windows.Forms
Public Class Dialog1
Dim Client As New Net.WebClient()
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
Me.Close()
End Sub
'Download file from web.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DR As DialogResult = FolderBrowserDialog1.ShowDialog
If DR = Windows.Forms.DialogResult.OK Then
Client.DownloadFile(Web_update.Downuri, _
FolderBrowserDialog1.SelectedPath.ToString & _
"\Program_Update_" & Date.Today.ToShortDateString.ToString & ".zip")
End If
Me.Close()
End Sub
'Download file from web to Temp-directory and run.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Client.DownloadFile(Web_update.Downuri, _
My.Computer.FileSystem.SpecialDirectories.Temp.ToString & "\Program_Update.zip")
Process.Start(My.Computer.FileSystem.SpecialDirectories.Temp.ToString & _
"\Program_Update.zip")
Application.Exit()
End Sub
End Class
In Form1 I have StatusStrip1 which contains ToolStripSplitButton1 and this contains Check For Updates-ToolStripMenuItem
Form1.vb
Private Sub CheckForUpdatesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckForUpdatesToolStripMenuItem.Click
Web_update.Main()
End Sub
End Class
version.html-file contains only the number of current version for example
1005
and nothing else, so there is no dots between numbers.
Program.Zip-file contains 2 files which contais Setup.exe and Program_Setup.msi whitch you get when you build your Setup-project
You need to compress these files manually.
I hope this helps someone to get Updating of program working.

I added the Version.zip-file witch contains my version.vb, Dialog1.vb, Dialog1.resx and Dialog1.Designer.vb-files
Attached File(s)
-
Version.zip (4.65K)
Number of downloads: 2121
This post has been edited by TEH: 04 February 2010 - 02:34 AM






MultiQuote





|