Chilkat Event Callbacks in VB.NET (.NET Framework)

Here’s a VB .NET Framework example using the Chilkat .NET Framework assembly to create a Zip archive with support for the following event callbacks:

  • PercentDone — to track zip creation progress
  • AbortCheck — to allow canceling the operation
  • ProgressInfo — to monitor additional info

While this example focuses on callbacks for creating a .zip, the same method applies to other Chilkat .NET Framework classes like Http, Ftp2, MailMan, and Rest.



Imports Chilkat

Public Class Form1

    Dim WithEvents zip As New Chilkat.Zip

    Private Sub zip_OnAbortCheck(sender As Object, args As Chilkat.AbortCheckEventArgs) Handles zip.OnAbortCheck
        Application.DoEvents()
        If (CheckBox1.Checked) Then
            args.Abort = True
        End If
    End Sub

    Private Sub zip_OnPercentDone(sender As Object, args As Chilkat.PercentDoneEventArgs) Handles zip.OnPercentDone

        ProgressBar1.Value = args.PercentDone
        Application.DoEvents()

        If (CheckBox1.Checked) Then
            args.Abort = True
        End If

    End Sub

    Private Sub zip_OnProgressInfo(sender As Object, args As Chilkat.ProgressInfoEventArgs) Handles zip.OnProgressInfo
        Debug.WriteLine($"[ProgressInfo] {args.Name}: {args.Value}")
    End Sub


    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim glob As New Chilkat.Global
        Dim success As Boolean = glob.UnlockBundle("YOUR_CHILKAT_UNLOCK_CODE")

        Dim zipPath As String = "c:/temp/myFiles.zip"

        ' Initialize the zip object, which also sets the FileName property to the path of the zip to be created.
        zip.NewZip(zipPath)

        ' Append references to files to be zipped.
        Dim recurse As Boolean = True
        success = zip.AppendFiles("c:/workarea/*", recurse)
        If (success = False) Then
            Debug.WriteLine(zip.LastErrorText)
            Exit Sub
        End If

        ' Write the .zip and close the zip file (and clears the zip object).
        success = zip.WriteZipAndClose()
        If (success = False) Then
            Debug.WriteLine(zip.LastErrorText)
            Exit Sub
        End If

        Debug.WriteLine("Successfully created " & zipPath)
    End Sub
End Class