Xceed Zip for COM/ActiveX on x86/x64 Documentation
Getting started quickly / Listing the contents of a zip file
In This Topic
    Listing the contents of a zip file
    In This Topic

    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.

    Basic listing by event

    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  

    ' Don't forget to put an Xceed Zip control on a form
    Dim ResultCode As xcdError
    Call XceedZip1.License( "your license key" )

    XceedZip1.ZipFilename = "c:\backups\My documents.zip"
    ResultCode = XceedZip1.ListZipContents
    If ResultCode = xerSuccess then
    MsgBox "Files listed successfully."
    Else
    MsgBox XceedZip1.GetErrorDescription(xvtError, ResultCode)
    EndIf
    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:
    ListBox1.AddItem sFilename + " size=" + Str(lCompressedSize)

    Here is sample Delphi code for these 4 steps (excluding the code for the ListingFile event):

    Delphi  

    var xErr : xcdError;
    begin
    XceedZip1.License( 'your license key' );

    XceedZip1.ZipFilename := 'c:\backups\My documents.zip';

    xErr := XceedZip1.ListZipContents;

    ShowMessage( XceedZip1.GetErrorDescription( xvtError, xErr ) );
    end;

    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  

    ListBox1.Items.Add( sFilename + ' size=' + IntToStr( lCompressedSize ) );

    Things you should consider

    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:

    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.