RemoveEntry from PW Protected Zip

May 27, 2009 at 6:32 PM

I am creating a password-protected zip containing a number of files and then later allowing the user to select files to remove from the zip.  This works fine if the zip is not password protected, but if I password protect the zip when I create it (sample code below) I get "FileNotFoundException" ("file2.txt") when I later remove a file from the zip and try to save it.

 

    Sub AddFiles()
        Dim zip As New Ionic.Zip.ZipFile()
        zip.Password = "password"
        zip.Encryption = Ionic.Zip.EncryptionAlgorithm.WinZipAes256
        Dim entry1 As Ionic.Zip.ZipEntry = zip.AddFile("c:\file1.txt")
        zip.AddFile("c:\file2.txt")
        zip.Save(ZipFileName)
    End Sub

    Sub RemoveFile()
        Dim zip As New Ionic.Zip.ZipFile(ZipFileName)
        zip.RemoveEntry("c:\file1.txt")
        zip.Save(ZipFileName)
    End Sub

Coordinator
May 27, 2009 at 8:04 PM

Taking your code, I could not reproduce the "FileNotFoundException" you reported. 

Using v1.8.3.11, your code works, as expected.

Using v1.7.2.20, when I call Save() after removing an entry from a password protected file, I get an exception, but not the one you reported.  I get, instead, Ionic.Zip.BadPasswordException .  This seems like a bug, but it is not the problem you reported.

What version of the library are you using?

 

May 27, 2009 at 8:36 PM

I was using 1.7.2.16.  When I switched to 1.8.3.11, the code worked fine, just as you said. 

Thanks for your help.

Coordinator
May 27, 2009 at 9:17 PM

Glad you got it working. After some further testing I was able to reproduce that FileNotFoundException.  It's a bug, that was fixed in v1.8 but the fix was not back-ported to v1.7. I'm doing that now.

May 27, 2009 at 9:29 PM

Thanks for the follow-up.  I'll give v1.7 a try after it's updated.

Coordinator
May 27, 2009 at 10:02 PM

v1.7.2.21 is now available.  It has this fix.

Thanks