Zip Component, Email Component, Encryption Component ActiveX Control for Zip Compression .NET Components for ASP.NET
ActiveX and .NET Components for Zip Compression, Encryption, Email, XML, S/MIME, HTML Email, Character Encoding, Digital Certificates, FTP, and more ASP Email ActiveX Component

Index of Chilkat Blog Posts

June 13, 2007

VB.NET HTTP Download with Progress Monitoring and Abort

This is an example program that demonstrates how to do an HTTP download in VB.NET with progress monitoring and abort capabilities.

A few notes:

  1. Declare the Chilkat.Http object WithEvents
  2. Don’t forget to set Chilkat.Http.EnableEvents = true, otherwise you won’t get callbacks.
  3. Use the dropdown box in Visual Studio to select your Chilkat.Http object, then select the OnPercentDone event. VB.NET will create the event callback function for you. You can then add your application code to the event callback.

Here is an example:

    ' Declare the Chilkat.Http object WithEvents
    Dim WithEvents m_http As New Chilkat.Http
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ' The unlock is only needed once at the beginning of the program.
        ' As long as UnlockComponent is called once, additional instances
        ' of Chilkat.Http can be created and used without needing to call UnlockComponent.
        m_http.UnlockComponent("anything for 30-day trial")
        ' Don't forget to enable events...
        m_http.EnableEvents = True
        ' Download Python for Windows
        Dim success As Boolean
        success = m_http.Download("", "python-2.5.1.msi")
        If (success) Then
            MessageBox.Show("Download Successful!")
        End If
    End Sub
    ' This is the event callback.  It is called periodically whenever the percentage completion
    ' increases.  For short downloads, it will likely not be called once for each 1% increment.
    ' However, you should always get a final callback where args.PercentDone = 100,
    ' in the case of a successful download.
    Private Sub m_http_OnPercentDone(ByVal sender As Object, ByVal args As Chilkat.PercentDoneEventArgs) Handles m_http.OnPercentDone
        ProgressBar1.Value = args.PercentDone
        ' To abort the HTTP download at any point, simply set args.Abort = true
        ' (uncomment the following lines to abort at 50% completion)
        'If (args.PercentDone >= 50) Then
        '   args.Abort = True
        'End If
    End Sub

Privacy Statement. Copyright 2000-2011 Chilkat Software, Inc. All rights reserved.
Send feedback to

Components for Microsoft Windows XP, 2000, 2003 Server, Vista, Windows 7, and Windows 95/98/NT4.