Xceed Zip Compression Library Documentation
PreviewFiles method and PreviewingFiles event example for VB
Example topics > PreviewFiles method and PreviewingFiles event example for VB

The first function of the following code previews all the files that match the "C:\DATA\*.dat" wildcard and that are bigger than 65536 bytes. Keep in mind that any sub-directories in C:\DATA will also be searched for *.dat files, because the ProcessSubfolders property is set to True by default, even if the code below doesn't explicitly set it. The second function below is a handler written for the PreviewingFile event that displays each file previewed, along with some other of the file's information, in a listbox. The third function below is a handler written for the ProcessCompleted event, that adds summary information into the same 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 previewing.

Visual Basic Copy Code

Sub Command1_Click()

   Dim ResultCode As xcdError  

   Call XceedZip1.License( "your license key" ) 

   XceedZip1.FilesToProcess = "c:\data\*.dat" 

   XceedZip1.MinSizeToProcess = 65536 ' Added this as an example of what you can do with the PreviewFiles method. This line makes Xceed Zip only preview files larger than 64K.  

   ' We don't need to set the ZipFilename property, because PreviewFiles doesn't look at what's in the Zip file already.    

   ' Now call the PreviewFiles method (without the optional parameter) 
   ResultCode = XceedZip1.PreviewFiles  

   ' If we wanted to know the total compressed size of all the previewed files, we could have used this line instead: 

   ' ResultCode = XceedZip1.PreviewFiles(True) 

   ' If you do this, the ProcessCompleted event's lBytesOutput parameter will contain the total compressed size.  

   ' Now we check the return value  

   If ResultCode <> xerSuccess Then 
      MsgBox "Unsuccessful. Error #" & Str(ResultCode) & " occurred. " & "Description: " & _ XceedZip1.GetErrorDescription(xvtError, ResultCode) 
   Else 
      MsgBox "Operation successful." 
   End If   
End Sub

Here's the handler for the PreviewingFile event. It will add each previewed file's name and info to the listbox.

Visual Basic Copy Code

Private Sub XceedZip1_PreviewingFile(ByVal sFilename As String, ByVal sSourceFilename As String, _
                                     ByVal lSize As Long, _
                                     ByVal xAttributes As XceedZipLibCtl.xcdFileAttributes, _
                                     ByVal dtLastModified As Date, _
                                     ByVal dtLastAccessed As Date, ByVal dtCreated As Date, _
                                     ByVal bExcluded As Boolean, _
                                     ByVal xReason As XceedZipLibCtl.xcdSkippingReason)

   List1.AddItem "Filename : " & sFilename 
   List1.AddItem "Date : " & dtCreated 
   List1.AddItem "Size : " & lSize 
End Sub

Here's the handler for the ProcessCompleted event. It adds summary information to the listbox.

Visual Basic Copy Code

Private Sub XceedZip1_ProcessCompleted(ByVal lFilesTotal As Long, ByVal lFilesProcessed As Long, _
                                       ByVal lFilesSkipped As Long, ByVal lBytesTotal As Long, _
                                       ByVal lBytesProcessed As Long, _
                                       ByVal lBytesSkipped As Long, ByVal lBytesOutput As Long, _
                                       ByVal nCompressionRatio As Integer, _
                                       ByVal xResult As XceedZipLibCtl.xcdError) 

   List1.AddItem "=====================================" 
   List1.AddItem "Summary : " 
   List1.AddItem "" 
   List1.AddItem "Total number of Files :" & lFilesTotal 

   List1.AddItem "Total compressed Size : " & lBytesOutput ' This information is only valid if you called the PreviewFiles method with the optional parameter set to True. 

End Sub