Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Unzip with Progress Monitoring Event Callbacks
VB.NET sample program demonstrating the unzip progress monitoring event callbacks available with the Chilkat Zip component. ' When using events, we must declare the variable as a global or
' class member WithEvents
' Once it is declared, we can select the "zip" object from
' the VB.NET IDE to see the events. If you select the event
' from the dropdown, Visual Studio will create the callback
' subroutine for you.
Dim WithEvents zip As New Chilkat.Zip()
' Unzip with progress monitoring callbacks.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' This must be called once at the beginning of your program.
zip.UnlockComponent("Anything for 30-day trial")
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
' Don't forget to enable events.
zip.EnableEvents = True
' Open a zip archive.
Dim success As Boolean
success = zip.OpenZip("myZip.zip")
If (Not success) Then
MessageBox.Show(zip.LastErrorText)
Exit Sub
End If
Dim dirPath As String
Dim numFilesUnzipped As Integer
dirPath = "./myZip"
' Unzip to a sub-directory relative to the current working directory
' of the calling process. If the myZip directory does not exist,
' it is automatically created.
numFilesUnzipped = zip.Unzip(dirPath)
If (numFilesUnzipped < 0) Then
MessageBox.Show(zip.LastErrorText)
Exit Sub
End If
zip.CloseZip()
End Sub
' When unzipping large Zips, there may be a long time between percent-done callbacks.
' The OnAbortCheck callback is called about once every .5 seconds that elapse without
' a percent-done callback.
Private Sub zip_OnAbortCheck(ByVal sender As Object, ByVal args As Chilkat.AbortCheckEventArgs) Handles zip.OnAbortCheck
' To abort the unzipping, set args.Abort = true:
' if (....) then
' args.Abort = True
' end if
End Sub
' Called during unzipping to monitor the percentage progress to completion.
Private Sub zip_OnUnzipPercentDone(ByVal sender As Object, ByVal args As Chilkat.UnzipPercentDoneEventArgs) Handles zip.OnUnzipPercentDone
' args contains two members:
' args.Abort: Set this boolean flag to force the unzip to abort.
' args.PercentDone: Contains an integer having a value between 1 and 100.
ProgressBar1.Value = args.PercentDone
' The following commented-out lines will abort the unzip after it is 50% complete.
'If (args.PercentDone >= 50) Then
' args.Abort = True
'End If
End Sub
' Called during the unzip process for each file before it is to be unzipped.
Private Sub zip_OnToBeUnzipped(ByVal sender As Object, ByVal args As Chilkat.ToBeUnzippedEventArgs) Handles zip.OnToBeUnzipped
' args contains five members:
' args.Exclude: You may set this to true to prevent the file from being unzipped.
' args.CompressedSize: The compressed size in bytes.
' args.FileSize: The original uncompressed size of the file.
' args.FileName: The filename.
' args.IsDirectory: True if the filename is a directory, false otherwise.
If (args.IsDirectory) Then
ListBox1.Items.Add("DIR: " + args.FileName)
Else
ListBox1.Items.Add(args.FileName)
End If
End Sub
' Called once for each file after it is unzipped.
Private Sub zip_OnFileUnzipped(ByVal sender As Object, ByVal args As Chilkat.FileUnzippedEventArgs) Handles zip.OnFileUnzipped
' args contains five members:
' args.Abort: You may set this to true to abort the unzip process.
' args.CompressedSize: The compressed size in bytes.
' args.FileSize: The original uncompressed size of the file.
' args.FileName: The filename.
' args.IsDirectory: True if the filename is a directory, false otherwise.
If (args.IsDirectory) Then
ListBox2.Items.Add("DIR: " + args.FileName)
Else
ListBox2.Items.Add(args.FileName)
End If
End Sub
' Called once at the very beginning of an unzip.
Private Sub zip_OnUnzipBegin(ByVal sender As Object, ByVal args As System.EventArgs) Handles zip.OnUnzipBegin
End Sub
' Called once at the very end of an unzip.
Private Sub zip_OnUnzipEnd(ByVal sender As Object, ByVal args As System.EventArgs) Handles zip.OnUnzipEnd
End Sub
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.