40. Application Updater

In the previous tutorial, we covered using the HttpWebRequest and HttpWebResponse to obtain the source code of a web page. In this tutorial, we make use of that by creating an application that will allow us to check for any new updates.

Code

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://h1.ripway.com/TeachMeComputer/currentversion.txt")
        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
            MessageBox.Show("You have the current version")
        Else
            MessageBox.Show("Newer version available")
        End If
    End Sub

End Class