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
Event Callbacks when Adding File References to the Zip Object
Demonstrates event callbacks for the AppendFiles and AppendFilesEx methods. ' 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()
' Demonstrates event callbacks when adding references to files with
' the AppendFiles(Ex) method. The AppendFiles method simply adds file
' references to the zip object. It may be called multiple times to add
' different files or different directory sub-trees. The .zip file is
' created when WriteZip is called. It is at that point when all files
' referenced by the zip object are gathered and compressed into the zip archive.
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.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".
' The AppendFiles callbacks are listed in the subroutines below...
'
' NOTE: The AppendFilesEx method does not create a .zip file on disk.
' It simply adds file references to the zip. When WriteZip (or WriteExe, WriteZipAndClose, etc.) is called,
' all files and data referenced by the Zip object are included in the .zip that is created.
success = zip.AppendFilesEx("c:/temp/a/*", recurseDirectories, saveExtraPath, archiveOnly, includeHidden, includeSystem)
If (Not success) Then
MessageBox.Show(zip.LastErrorText)
Exit Sub
End If
'success = zip.WriteZipAndClose()
'If (Not success) Then
'MessageBox.Show(zip.LastErrorText)
'Exit Sub
'End If
MessageBox.Show("Done!")
End Sub
' Called once at the very beginning of an AppendFiles(Ex) method.
Private Sub zip_OnAddFilesBegin(ByVal sender As Object, ByVal args As System.EventArgs) Handles zip.OnAddFilesBegin
End Sub
' Called once at the very end of an AppendFiles(Ex) method.
Private Sub zip_OnAddFilesEnd(ByVal sender As Object, ByVal args As System.EventArgs) Handles zip.OnAddFilesEnd
End Sub
' Called once for each directory before the reference to the file is appended
' to the Zip object.
Private Sub zip_OnDirToBeAdded(ByVal sender As Object, ByVal args As Chilkat.DirToBeAddedEventArgs) Handles zip.OnDirToBeAdded
' args contains two members:
' args.Exclude - Set this to True to exclude the directory from being added.
' args.DirName - The directory path to be added.
ListBox1.Items.Add("DIR: " + args.DirName)
End Sub
' Called once for each file before the reference to the file is appended
' to the Zip object.
Private Sub zip_OnToBeAdded(ByVal sender As Object, ByVal args As Chilkat.ToBeAddedEventArgs) Handles zip.OnToBeAdded
' args contains three members:
' args.Exclude - Set this to True to prevent the file from being added.
' args.FileName - The filename (and path) of the file to be added.
' args.FileSize - The size of the file (in bytes) to be added.
ListBox1.Items.Add(args.FileName)
End Sub
' Called once for each file after a reference to it has been added to the zip object.
Private Sub zip_OnFileAdded(ByVal sender As Object, ByVal args As Chilkat.FileAddedEventArgs) Handles zip.OnFileAdded
' args contains three members:
' args.Abort - Set this to True to abort the AppendFiles(Ex) method.
' args.FileName - The filename (and path) of the file to be added.
' args.FileSize - The size of the file (in bytes) to be added.
ListBox2.Items.Add(args.FileName)
End Sub
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.