Xceed .NET Libraries Documentation
BuildingZipByteProgression event

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

The BuildingZipByteProgression event is raised when the target zip file is being built from the temporary files, for every 8 kb processed. 

Keep in mind that using the BuildingZipByteProgression event increases the time it takes to process the temporary files. The reason behind this is that the data associated with the file 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 actual processing of the files.

Purpose

The main purpose of the BuildingZipByteProgression 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 BuildingZipByteProgression event, the following steps must be performed:

  • Create a reference to a ZipEvents object. 

  • Subscribe to the BuildingZipByteProgression event of the ZipEvents object using the BuildingZipByteProgressionEventHandler 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 OnBuildingZipByteProgression. 

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

Basic steps - VB.NET

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

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

  • Select the BuildingZipByteProgression 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

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

folder.Delete( zEvents, Nothing )

Private Sub zEvents_BuildingZipByteProgression(ByVal sender As Object, _
                                                  ByVal e As Xceed.FileSystem.ByteProgressionEventArgs) _
                                                  Handles zEvents.BuildingZipByteProgression)

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


End Sub

C# Copy Code

using Xceed.Zip;
using Xceed.FileSystem;


ZipEvents zEvents = new ZipEvents();
zEvents.BuildingZipByteProgression += new BuildingZipByteProgressionEventHandler( OnBuildingZipByteProgression );
 
ZippedFolder folder = new ZippedFolder( new DiskFile( @"c:\test.zip" ), @"\folder" );
folder. Delete( zEvents, null );
  
//This method will handle the BuildingZipByteProgression events that are raised.
public static void OnBuildingZipByteProgression( object sender, ByteProgressionEventArgs e )
{
   Console.WriteLine( "Processed {0} bytes of {1} on {2}.",
                      e.CurrentFileBytes.Processed,
                      e.CurrentFileBytes.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.BuildingZipByteProgression -= new BuildingZipByteProgressionEventHandler( OnBuildingZipByteProgression );