An event handler invoked before, during, and after extraction of
entries in the zip archive.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public event EventHandler<ExtractProgressEventArgs> ExtractProgress
Public Event ExtractProgress As EventHandler(Of ExtractProgressEventArgs)
public: event EventHandler<ExtractProgressEventArgs^>^ ExtractProgress { void add (EventHandler<ExtractProgressEventArgs^>^ value); void remove (EventHandler<ExtractProgressEventArgs^>^ value); }
Remarks
Depending on the particular event, different properties on the ExtractProgressEventArgs parameter are set. The following table summarizes the available EventTypes and the conditions under which this event handler is invoked with a ExtractProgressEventArgs with the given EventType.
value of EntryType | Meaning and conditions |
---|---|
ZipProgressEventType.Extracting_BeforeExtractAll |
Set when ExtractAll() begins. The ArchiveName, Overwrite, and
ExtractLocation properties are meaningful. |
ZipProgressEventType.Extracting_AfterExtractAll |
Set when ExtractAll() has completed. The ArchiveName, Overwrite,
and ExtractLocation properties are meaningful.
|
ZipProgressEventType.Extracting_BeforeExtractEntry |
Set when an Extract() on an entry in the ZipFile has begun.
Properties that are meaningful: ArchiveName, EntriesTotal,
CurrentEntry, Overwrite, ExtractLocation, EntriesExtracted.
|
ZipProgressEventType.Extracting_AfterExtractEntry |
Set when an Extract() on an entry in the ZipFile has completed.
Properties that are meaningful: ArchiveName, EntriesTotal,
CurrentEntry, Overwrite, ExtractLocation, EntriesExtracted.
|
ZipProgressEventType.Extracting_EntryBytesWritten |
Set within a call to Extract() on an entry in the ZipFile, as data
is extracted for the entry. Properties that are meaningful:
ArchiveName, CurrentEntry, BytesTransferred, TotalBytesToTransfer.
|
ZipProgressEventType.Extracting_ExtractEntryWouldOverwrite |
Set within a call to Extract() on an entry in the ZipFile, when the
extraction would overwrite an existing file. This event type is used
only when ExtractExistingFileAction on the ZipFile or
ZipEntry is set to InvokeExtractProgressEvent.
|
Examples
CopyC#
private static bool justHadByteUpdate = false; public static void ExtractProgress(object sender, ExtractProgressEventArgs e) { if(e.EventType == ZipProgressEventType.Extracting_EntryBytesWritten) { if (justHadByteUpdate) Console.SetCursorPosition(0, Console.CursorTop); Console.Write(" {0}/{1} ({2:N0}%)", e.BytesTransferred, e.TotalBytesToTransfer, e.BytesTransferred / (0.01 * e.TotalBytesToTransfer )); justHadByteUpdate = true; } else if(e.EventType == ZipProgressEventType.Extracting_BeforeExtractEntry) { if (justHadByteUpdate) Console.WriteLine(); Console.WriteLine("Extracting: {0}", e.CurrentEntry.FileName); justHadByteUpdate= false; } } public static ExtractZip(string zipToExtract, string directory) { string TargetDirectory= "extract"; using (var zip = ZipFile.Read(zipToExtract)) { zip.ExtractProgress += ExtractProgress; foreach (var e in zip1) { e.Extract(TargetDirectory, true); } } }
CopyVB.NET
Public Shared Sub Main(ByVal args As String()) Dim ZipToUnpack As String = "C1P3SML.zip" Dim TargetDir As String = "ExtractTest_Extract" Console.WriteLine("Extracting file {0} to {1}", ZipToUnpack, TargetDir) Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack) AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress Dim e As ZipEntry For Each e In zip1 e.Extract(TargetDir, True) Next End Using End Sub Private Shared justHadByteUpdate As Boolean = False Public Shared Sub MyExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs) If (e.EventType = ZipProgressEventType.Extracting_EntryBytesWritten) Then If ExtractTest.justHadByteUpdate Then Console.SetCursorPosition(0, Console.CursorTop) End If Console.Write(" {0}/{1} ({2:N0}%)", e.BytesTransferred, e.TotalBytesToTransfer, (CDbl(e.BytesTransferred) / (0.01 * e.TotalBytesToTransfer))) ExtractTest.justHadByteUpdate = True ElseIf (e.EventType = ZipProgressEventType.Extracting_BeforeExtractEntry) Then If ExtractTest.justHadByteUpdate Then Console.WriteLine End If Console.WriteLine("Extracting: {0}", e.CurrentEntry.FileName) ExtractTest.justHadByteUpdate = False End If End Sub
See Also