AddProgress Event

DotNetZip

Ionic Zip Library v1.9.1.6 AddProgress Event
ReferenceIonic.ZipZipFileAddProgress
An event handler invoked before, during, and after Adding entries to a zip archive.
Declaration Syntax
C# Visual Basic Visual C++
public event EventHandler<AddProgressEventArgs> AddProgress
Public Event AddProgress As EventHandler(Of AddProgressEventArgs)
public:
 event EventHandler<AddProgressEventArgs^>^ AddProgress {
	void add (EventHandler<AddProgressEventArgs^>^ value);
	void remove (EventHandler<AddProgressEventArgs^>^ value);
}
Remarks
Adding a large number of entries to a zip file can take a long time. For example, when calling AddDirectory(String) on a directory that contains 50,000 files, it could take 3 minutes or so. This event handler allws an application to track the progress of the Add operation, and to optionally cancel a lengthy Add operation.
Examples
CopyC#
int _numEntriesToAdd= 0;
int _numEntriesAdded= 0;
void AddProgressHandler(object sender, AddProgressEventArgs e)
{
    switch (e.EventType)
    {
        case ZipProgressEventType.Adding_Started:
            Console.WriteLine("Adding files to the zip...");
            break;
        case ZipProgressEventType.Adding_AfterAddEntry:
            _numEntriesAdded++;
            Console.WriteLine(String.Format("Adding file {0}/{1} :: {2}",
                                     _numEntriesAdded, _numEntriesToAdd, e.CurrentEntry.FileName));
            break;
        case ZipProgressEventType.Adding_Completed:
            Console.WriteLine("Added all files");
            break;
    }
}

void CreateTheZip()
{
    using (ZipFile zip = new ZipFile())
    {
        zip.AddProgress += AddProgressHandler;
        zip.AddDirectory(System.IO.Path.GetFileName(DirToZip));
        zip.Save(ZipFileToCreate);
    }
}
CopyVB.NET
Private Sub AddProgressHandler(ByVal sender As Object, ByVal e As AddProgressEventArgs)
    Select Case e.EventType
        Case ZipProgressEventType.Adding_Started
            Console.WriteLine("Adding files to the zip...")
            Exit Select
        Case ZipProgressEventType.Adding_AfterAddEntry
            Console.WriteLine(String.Format("Adding file {0}", e.CurrentEntry.FileName))
            Exit Select
        Case ZipProgressEventType.Adding_Completed
            Console.WriteLine("Added all files")
            Exit Select
    End Select
End Sub

Sub CreateTheZip()
    Using zip as ZipFile = New ZipFile
        AddHandler zip.AddProgress, AddressOf AddProgressHandler
        zip.AddDirectory(System.IO.Path.GetFileName(DirToZip))
        zip.Save(ZipFileToCreate);
    End Using
End Sub

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)