Looking for VB examples for 1.7

May 19, 2009 at 1:38 PM

Are there any samples, explanations, or tips dealing with the changed namespace of 1.7 (VB.NET 2008)? Because when I downloaded the binary I again got a Ionic.Utils.dll and I cannot find anything that would help me show a progress report during the .save() operation.

There are simply two things I want to do: speed up the way the resulting ZIP is saved (adding recursive entries works fine and fast) or at least report to the user what the ZIP operation is doing. And on the other side of the coin I would like to unpack files without whatever folder structure may be inside the ZIP (these are downloads, so I have no control over their creation). Thus far I have not found anyway to do either.

Any & all help would be appreciated.

May 19, 2009 at 5:03 PM
Edited May 19, 2009 at 5:10 PM

v1.7 uses Ionic.Zip as the namespace, replacing Ionic.Utils.Zip.  The name of the DLL is Ionic.Zip.dll.  There is no Ionic.Utils.dll - there never was a file by that name in any release of DotNetZip.  typo on your part?

If you still see an Ionic.Utils.Zip namespace in Visual Studio, then you are referencing an older version of the library.  You can find out the version of the library you are using at runtime with the ZipFile.LibraryVersion property. It is a static (Shared in VB) property.

To address your two things:

  1. To report progress, you have the events: ReadProgress, SaveProgress and ExtractProgress on the ZipFile class.  They work pretty much like events on any .NET class. Add an event handler and you will get notified.  The help file (.chm file) includes complete documentation for these events, including examples in VB source code for how to do this. Also the 3rd example on   this page  includes an example with an ExtractProgress event handler in VB.
  2. To extract and flatten the file structure, you have several options.  I would suggest renaming the entry, and then extracting it.  

Here's a code example that address both of your issues:

    Private Shared justHadByteUpdate As Boolean = False
    ' if this is a Winforms GUI, will want to update a progress bar or 
    ' similar.
    Private 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
            End If
            Console.WriteLine("Extracting: {0}", e.NameOfLatestEntry)
            ExtractTest.justHadByteUpdate = False
        End If
    End Sub

    Private Sub MyExtract
      Dim Overwrite as ExtractExistingFileAction = ExtractExistingFileAction.OverwriteSilently
      Dim ZipToUnpack As String = "C1P3SML.zip"  
      Dim UnpackDirectory As String = "Extracted Files"
      StatusMessage.Text = String.Format("Extracting file {0} to {1}", ZipToUnpack, UnpackDirectory )
      Using zip1 As ZipFile = ZipFile.Read(ZipToUnpack)
           ' register a progress event for extraction   
	  AddHandler zip1.ExtractProgress, AddressOf MyExtractProgress   
	  Dim e As ZipEntry   
	  ' here, we extract every entry, but we could extract conditionally,
	  ' based on entry name, size, date, checkbox status, etc.   
	  For Each e In zip1
               ' rename the entry to remove the path
               e.FileName = System.IO.Path.GetFileName(e.FileName)
               ' extract that entry into the directory
	      e.Extract(UnpackDirectory, Overwrite)
      End Using   
    End Sub
May 19, 2009 at 6:32 PM
Edited May 19, 2009 at 6:58 PM

Thanks for the example; I'll convert it to my usage. As for the version, The reference clearly states Ionic.Util.zip.dll, Version (what I wrote earlier was indeed a typo) - as I found it in the binary download. Up until then I was using 1.6.x.xx. What surprises me in both cases is how excrutiatingly slow the archiving process is: WinZip, even older versions, provided an only marginally smaller archive in 1/5th of the of the exact same files. I thus use it only for the smallest of backups and, of course, for extraction which is perfectly find, speed-wise.

May 19, 2009 at 11:12 PM

Ahh, yes, you are using a preview release of v1.7. 

The first "official" release was v1.7.2.4. http://dotnetzip.codeplex.com/Thread/View.aspx?ThreadId=46688   Up until then, things were still changing, including, as you have seen, the namespace. 

I'd encourage you to get the latest v1.7 release. 

If you want increased speed, I can suggest v1.8, which is packaged as a RELEASE dll, and consequently delivers significantly better performance that v1.7, which was delivered only as a DEBUG dll.  But, v1.8 is still in preview!

I don't know how you are doing the timing comparisons; I'd be interested to hear your methodology, in particular how you are able to get a VB.NET app to use the winzip DLL.  Or maybe you are just using the command-line or GUI tools for timing comparisons?  What I've found is that WinZip is very fast, but not very accessible to .NET programs. 

Sorry DotNetZip has been so excruciating to you!


May 20, 2009 at 8:29 AM

Not excrutiating at all; for the most part I use your library for extracting and that all works brilliantly. Maybe you would consider the idea of adding a switch that would permit easy switching extract without folder? Just dreaming.

As for the comparative test - no, I did not extract the DLL but simply timed the WinZIP GUI. I'll be trying 1.8 today and see what happens.

May 22, 2009 at 10:34 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.