Xceed .NET Libraries Documentation
BuildingZipItemProgression event

Welcome to Xceed .NET, .NET Standard and Xamarin Libraries! > Basic Concepts > Events > BuildingZipItemProgression event

The BuildingZipItemProgression event is raised each time a temporary file is about to be added to the target zip file. 

Keep in mind that using the BuildingZipItemProgression event increases the time it takes to process the temporary files. The reason behind this is that the data will be scanned twice. The first time the files are scanned, information regarding the files will be accumulated ( filename, size, etc.. ). This is to allow accurate progress information to be returned during the second run.

Purpose

The main purpose of the BuildingZipItemProgression event is to provide feedback to the user during the process of moving the temporary files to the temporary zip file to prevent the application from appearing frozen.

Basic steps - C#

To subscribe to the BuildingZipItemProgression event, the following steps must be performed:

  • Create a reference to a ZipEvents object. 

  • Subscribe to the BuildingZipItemProgression event of the ZipEvents object using the BuildingZipItemProgressionEventHandler delegate class. 

  • Create a new method that will handle the events that are raised. For the purposes of this example, we will call the method OnBuildingZipItemProgression. 

  • Place the desired code in the newly created event handler.

Basic steps - VB.NET

To subscribe to the BuildingZipItemProgression event, the following steps must be performed:

  • Create a reference to a ZipEvents object using the WithEvents keyword. 

  • Select the BuildingZipItemProgression event from the list of available methods in the newly instantiated ZipEvents object. This is done in the same manner as, for example, adding the DoubleClick event of a ListBox.
    You can also subscribe to the event using the AddHandler/AddressOf statement. 

  • Place the desired code in the newly added event handler.

Demonstration

This example demonstrates how to delete a folder from within a zip file and display progress information during the operation.

VB.NET Copy Code

Imports Xceed.Zip
Imports Xceed.FileSystem

Dim WithEvents zEvents As New ZipEvents()
Dim folder As New ZippedFolder(New DiskFile("c:\test.zip"), "\folder")

folder.Delete( zEvents, Nothing )

Private Sub zEvents_BuildingZipItemProgression(ByVal sender As Object, _
                                                ByVal e As Xceed.FileSystem.ItemProgressionEventArgs) Handles zEvents.BuildingZipItemProgression

  ListBox1.Items.Add("Processed " + e.AllItems.Processed + _
                     " bytes of " + e.AllItems.Total + _
                     " on " + e.CurrentItem.Name)
End Sub

C# Copy Code
using Xceed.Zip;
using Xceed.FileSystem;
 
ZipEvents zEvents = new ZipEvents();
zEvents.BuildingZipItemProgression += new BuildingZipItemProgressionEventHandler( OnBuildingZipItemProgression );
 
ZippedFolder folder = new ZippedFolder( new DiskFile( @"c:\test.zip" ), "\folder" );
folder. Delete( zEvents, null );
  
//This method will handle the BuildingZipItemProgression events that are raised.
public static void OnBuildingZipItemProgression( object sender, ItemProgressionEventArgs e )
{
   Console.WriteLine( "Processed {0} bytes of {1} on {2}.",
                      e.AllItems.Processed,
                      e.AllItems.Total,
                      e.CurrentItem.Name );
}
 
//If you no longer wish to handle the events that are raised,
//you can unsubscribe from the event notifications by doing the following:
 
zEvents.BuildingZipItemProgression -= new BuildingZipItemProgressionEventHandler( OnBuildingZipItemProgression );