Xceed Zip Compression Library Documentation
ListZipContents method and ListingFile event example for VB
Example topics > ListZipContents method and ListingFile event example for VB

The first function of the following code lists all the files in the zip file "c:\test\my test.zip" that finish with ".txt". For each file listed, the ListingFile event will be triggered. The second function below is a handler written for the ListingFile event that displays each file listed, along with some other of the file's information, in a listbox. The code assumes you have placed a button, a listbox and an Xceed Zip control on a form, and named them Command1, List1 and XceedZip1 respectively. 

We start with the handler for the button's click event. The code will start the listing.

Visual Basic Copy Code

Sub Command1_Click() 

   Dim ResultCode As xcdError  

   Call XceedZip1.License( "your license key" ) 

   ' All properties keep their default values except the two below 
   XceedZip1.FilesToProcess = "*.txt" ' process only .txt files 
   XceedZip1.ZipFilename = "c:\test\my test.zip"  

   ' Start listing 
   ResultCode = XceedZip1.ListZipContents  

   ' Check the result code to make sure it worked properly 
   If (ResultCode <> xerSuccess) Then 
      List1.AddItem "Errors/warnings received, or a file was skipped." 
   End If 
End Sub

And here's the handler for the ListingFile event. It will add each file's name and info to the listbox.

Visual Basic Copy Code

Private Sub XceedZip1_ListingFile(ByVal sFilename As String, ByVal sComment As String, _
                                  ByVal lSize As Long, ByVal lCompressedSize As Long, _
                                  ByVal nCompressionRatio As Integer, _
                                  ByVal xAttributes As XceedZipLibCtl.xcdFileAttributes, _
                                  ByVal lCRC As Long, ByVal dtLastModified As Date, _
                                  ByVal dtLastAccessed As Date, ByVal dtCreated As Date, _
                                  ByVal xMethod As XceedZipLibCtl.xcdCompressionMethod, _
                                  ByVal bEncrypted As Boolean, ByVal lDiskNumber As Long, _
                                  ByVal bExcluded As Boolean, _
                                  ByVal xReason As XceedZipLibCtl.xcdSkippingReason) 

  List1.AddItem "Filename: " & sFilename 
  List1.AddItem " Uncompressed size: " & Str(lSize) 
  List1.AddItem " Compressed size: " & Str(lCompressedSize) 
  List1.AddItem " Compression ratio: " & Str(nCompressionRatio) 
End Sub