problems with unzip example

May 12, 2009 at 6:56 PM

I am using the code below, but Visual Studio always gives me this error:

"MyExtractProgress is not declared"

What should I declare it as?

  Dim ZipToUnpack As String = "C1P3SML.zip"  
Dim TargetDir As String = "C1P3SML"
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
' here, we extract every entry, but we could extract
' based on entry name, size, date, etc.
For Each e In zip1
e.Extract(TargetDir, ExtractExistingFileAction.OverwriteSilently)
Next
End Using

Thanks!

Coordinator
May 12, 2009 at 11:33 PM

It is an event handler; it's documented in the .chm file. If you look for the ZipFile.ExtractProgress property, it gives you an example that includes this code:

Public Shared Sub MyExtractProgress(ByVal sender As Object, ByVal e As ExtractProgressEventArgs)
    If (e.EventType Is ZipProgressEventType.Extracting_EntryBytesWritten) Then
        If ExtractTest.justHadByteUpdate Then
            Console.SetCursorPosition(0, Console.CursorTop)
        End If
        Console.Write("   {0}/{1} ({2:N0}%)", e.BytesWritten, e.TotalBytesToWrite, (CDbl(e.BytesWritten) / (0.01 * e.TotalBytesToWrite)))
        ExtractTest.justHadByteUpdate = True
    ElseIf (e.EventType Is ZipProgressEventType.Extracting_BeforeExtractEntry) Then
        If ExtractTest.justHadByteUpdate Then
            Console.WriteLine
        End If
        Console.WriteLine("Extracting: {0}", e.NameOfLatestEntry)
        ExtractTest.justHadByteUpdate = False
    End If
End Sub

Such an event handler would make sense only if you are using the code within a Cosnole app. If it is a WinForms app, you will want to update a status textbox, or a progressbar, or something else with each call of the event handler.