Xceed .NET Libraries Documentation
GatheringZipContentByteProgression event

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

The GatheringZipContentByteProgression event is raised during the step preceding the actual creation of the target zip file, where files to keep from the original zip file (the ones that were not modified) are gathered to a temporary location before overwriting the zip file. 

This event will only be raised when updating or modifying and existing zip file.

Purpose

The purpose of the GatheringZipContentByteProgression event is to provide progress information during the process of gathering the non-modified files from the original zip file so that applications do not appear to be idle.

Basic steps - C#

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

  • Create a reference to a ZipEvents object. 

  • Subscribe to the GatheringZipContentByteProgression event of the ZipEvents object using the GatheringZipContentByteProgressionEventHandler 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 OnGatheringZipContentByteProgression. 

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

Basic steps - VB.NET

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

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

  • Select the GatheringZipContentByteProgression 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 add a new file to an existing zip file and retrieve progress information during the gathering phase.

VB.NET Copy Code

Imports Xceed.Zip
Imports Xceed.FileSystem

Dim WithEvents zipEvents As New ZipEvents()

AddHandler zipEvents.GatheringZipContentByteProgression, AddressOf Me.OnGatheringByteProgression 

Dim zip As New ZipArchive( zipEvents, Nothing, New DiskFile( "d:\test.zip" ) )
Dim source As New DiskFile( "d:\images\xceed.jpg" )

source.CopyTo( zipEvents, Nothing, zip, true )

' In the event handler, we will display information regarding the current stage of the process.

Private Sub OnGatheringByteProgression( ByVal sender As Object, _
                                        ByVal e As ByteProgressionEventArgs )
  If e.AllFilesBytes.Percent < 100 Then
    Me.Text = e.AllFilesBytes.Percent.ToString() + _
              " % of non-modified files have been gathered. Please wait."
  Else
    Me.Text = "All non-modified files have been gathered from the " + _
              "original zip file. Starting update process."
  End If
End Sub

C# Copy Code

using Xceed.Zip;
using Xceed.FileSystem;

ZipEvents zipEvents = new ZipEvents();      

zipEvents.GatheringZipContentByteProgression += new
GatheringZipContentByteProgressionEventHandler( this.OnGatheringByteProgression );
 
ZipArchive zip = new ZipArchive( zipEvents, null, new DiskFile( @"d:\test.zip" ) );
 
DiskFile source = new DiskFile( @"d:\images\xceed.jpg" );
source.CopyTo( zipEvents, null, zip, true );  
 
// In the event handler, we will display information regarding the current stage of the process.
private void OnGatheringByteProgression( object sender, ByteProgressionEventArgs e )
{
  if( e.AllFilesBytes.Percent < 100 )
    this.Text = e.AllFilesBytes.Percent.ToString() + " 
               
% of non-modified files have been gathered. Please wait.";        
  else      
    this.Text = "All non-modified files have been gathered from the original zip file.
                 Starting update process.";        
}