Xceed Zip Compression Library can list the contents of a zip file either by triggering an event for each file that provides the file's name and other information, or by providing you with the complete listing (filenames and other information) in a collection object. Listing by event is easier and takes less memory, but is not always possible or useful. Listing by obtaining a collection object is slightly faster and allows you to enumerate the collection as often as you need without re-listing the zip file. See the Listing by collection getting started quickly topic if you are interested in the latter technique.
To list the contents of a zip file, perform the following 4 steps. Put the Xceed Zip control on a form, add a listbox to the form (if you want to display the list files in a listbox) and then:
Specify the zip file to list the contents of. To do this, set the ZipFilename property.
Tell Xceed Zip to start listing. To do this, call the ListZipContents method.
Obtain each filename and file info. To do this, write a handler for the ListingFile event.
Make sure it worked successfully. To do this, check the ListZipContents method's return value.
Here is sample VB code for these 4 steps (excluding the code for the ListingFile event):
Visual Basic | |
---|---|
|
Here is sample Delphi code for these 4 steps (excluding the code for the ListingFile event):
Delphi | |
---|---|
|
You will also need to put the following code into the ListingFile event handler. This code assumes you want to put the listed items in a listbox, and display only the filename and size:
Delphi | |
---|---|
|
The main questions you should ask yourself when listing files are:
What information do you need? The ListingFile event provides plenty of file information.
Are you possibly listing a spanned zip file? If so, write a handler for the InsertDisk event.
Do you want to display the status of the listing operation? See the GlobalStatus event.
Other questions you may want to consider are:
Do you want to list only certain types of files? See the filtering properties.
If there's anything else you need to do that's not mentioned here, consult the Properties topic, or search the index – chances are, Xceed Zip does what you need. If not, ask Xceed Software whether it is possible or not.