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
Zip with Progress Monitoring Event Callbacks
This VB.NET example program provides documentation on all the event callback functionality that exists when writing a Zip archive. ' 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()
' Zip with progress monitoring callback events.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' These two lines can 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
' Initialize our Zip object.
zip.NewZip("myZip.zip")
' Add some files.
Dim success As Boolean
Dim recurseDirectories As Boolean
Dim saveExtraPath As Boolean
Dim archiveOnly As Boolean
Dim includeHidden As Boolean
Dim includeSystem As Boolean
recurseDirectories = True
saveExtraPath = False
archiveOnly = False
includeHidden = True
includeSystem = True
' When SaveExtraPath is false, we will create a zip containing
' relative directory paths. In this case, the zip is created as if
' our current working directory was "c:/temp/a".
success = zip.AppendFilesEx("c:/temp/a/*", recurseDirectories, saveExtraPath, archiveOnly, includeHidden, includeSystem)
If (Not success) Then
MessageBox.Show(zip.LastErrorText)
Exit Sub
End If
' Writes "myZip.zip", which is the filename specified
' in the NewZip method.
' We could change the filename by setting the Filename property:
' zip.FileName = "somethingElse.zip"
'
' The callback methods are located in the subroutines below.
success = zip.WriteZipAndClose()
If (Not success) Then
MessageBox.Show(zip.LastErrorText)
Exit Sub
End If
MessageBox.Show("Zip successful!")
End Sub
' Callback to monitor the percentage progress completion of zipping.
' The zip operation can be aborted by setting the args.Abort property = true prior to returning.
Private Sub zip_OnWriteZipPercentDone(ByVal sender As Object, ByVal args As Chilkat.WriteZipPercentDoneEventArgs) Handles zip.OnWriteZipPercentDone
' args.PercentDone contains an integer value ranging from 1 to 100.
ProgressBar1.Value = args.PercentDone
' If we want to abort the zipping at any point, simply set args.Abort = true:
' If we uncomment the following lines, the zipping will be aborted once
' it is 50% complete:
'If (args.PercentDone >= 50) Then
'args.Abort = True
'End If
End Sub
' When creating 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 OnWriteZipPercentDone callback.
Private Sub zip_OnAbortCheck(ByVal sender As Object, ByVal args As Chilkat.AbortCheckEventArgs) Handles zip.OnAbortCheck
' To abort the zipping, set args.Abort = true:
' if (....) then
' args.Abort = True
' end if
End Sub
' The OnFileZipped callback is called for each file successfully appended to the zip.
Private Sub zip_OnFileZipped(ByVal sender As Object, ByVal args As Chilkat.FileZippedEventArgs) Handles zip.OnFileZipped
' args contains four members:
' args.Abort: You may set this to true to abort the zipping process.
' args.CompressedSize: The compressed size in bytes.
' args.FileSize: The original uncompressed size of the file.
' args.FileName: The filename as it will appear in the Zip.
ListBox2.Items.Add(args.FileName)
End Sub
' The OnToBeZipped event callback is called during the zip creation process, once for
' each file just before it is to be added to the zip. The application has the opportunity
' to exclude files by setting args.Exclude = True.
Private Sub zip_OnToBeZipped(ByVal sender As Object, ByVal args As Chilkat.ToBeZippedEventArgs) Handles zip.OnToBeZipped
' args contains three members:
' args.Exclude: You may set this to true to exclude the file from the zip.
' args.FileSize: The original uncompressed size of the file.
' args.FileName: The filename (including path) to be added.
End Sub
' This callback is called once at the beginning of the zip creation process.
Private Sub zip_OnWriteZipBegin(ByVal sender As Object, ByVal args As System.EventArgs) Handles zip.OnWriteZipBegin
' args contains no information...
End Sub
' This callback is called once at the end of the zip creation process.
Private Sub zip_OnWriteZipEnd(ByVal sender As Object, ByVal args As System.EventArgs) Handles zip.OnWriteZipEnd
' args contains no information...
End Sub
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.