Xceed .NET Libraries Documentation
Welcome to Xceed Data Manipulation Compoents for .NET and .NET Standard / Basic Concepts / Events / ReadingZipItemProgression event

In This Topic
    ReadingZipItemProgression event
    In This Topic

    The ReadingZipItemProgression event is raised whenever an item in a zipped folder is about to be read.

    Purpose

    When reading the central directory of large zip file, your application can appear to be frozen. The ReadingZipItemProgression event allows you to provide feedback to your user during this possibly lengthy operation.

    Basic steps - C#

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

    • Create a reference to a ZipEvents object. 

    • Subscribe to the ReadingZipItemProgression event of the ZipEvents object using the ReadingZipItemProgressionEventHandler 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 OnReadingZipItemProgression. 

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

    Basic steps - VB.NET

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

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

    • Select the ReadingZipItemProgression 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 contained within a zip file and display progress information while each item in the zip file is being read.

    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_ReadingZipItemProgression( ByVal sender As Object, _
                                                   ByVal e As ItemProgressionEventArgs ) 
                                                         Handles zEvents.ReadingZipItemProgression
       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.ReadingZipItemProgression += new ReadingZipItemProgressionEventHandler( OnReadingZipItemProgression );     

    ZippedFolder folder = new ZippedFolder( new DiskFile( @"c:\test.zip" ), "\folder" );   
    folder.Delete( zEvents, null );      

    //This method will handle the ReadingZipItemProgression events that are raised.   
    public void OnReadingZipItemProgression( 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.ReadingZipItemProgression -= new ReadingZipItemProgressionEventHandler( OnReadingZipItemProgression );