ZipError not firing with AddFiles

Apr 22, 2011 at 7:29 PM

I'm trying to get the ZipError event to fire when I have an error adding an entry.  I created my list of files I wan and then use the AddFiles method.  When I step through the code it enters the AddProgressHandler and exits the sub and I recieve an exception with "An item with the same key has already been added".  I'm opening an existing zip file and found that occasionally I might have an item in the zip that I'm trying to add again.  I would like to be able to use the ZipError event to capture that information and handle it.

    Sub Main

                    'Add the handlers
                    AddHandler objZip.AddProgress, AddressOf AddProgressHandler
                    AddHandler objZip.ZipError, AddressOf ZipErrorHandler

                    objZip.CompressionLevel = Ionic.Zlib.CompressionLevel.Default
                    objZip.AddFiles(strSelectedFiles, "")

    End Sub

    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

    Private Sub ZipErrorHandler(ByVal sender As Object, ByVal e As ZipErrorEventArgs)
        ' At this point, the application could prompt the user for an action to take.
        ' But in this case, this application will simply automatically skip the file, in case of error.
        Console.WriteLine("Zip Error,  entry {0}", e.CurrentEntry.FileName)
        Console.WriteLine("   Exception: {0}", e.Exception)
        ' set the desired ZipErrorAction on the CurrentEntry to communicate that to DotNetZip
        e.CurrentEntry.ZipErrorAction = ZipErrorAction.Skip
    End Sub

Aug 6, 2011 at 1:43 PM

ZipError doesn't work that way, currently.