11036 - The archive is not a valid Zip archive

Dec 9, 2008 at 3:03 PM
Hi, I am having trouble getting the library to create a valid zip file.
I am working in vb.net in an aspx partial class code page behind. I have pretty much just copied your exmple code and made only minor modification to the output location of the zipfile to use server.Mappath. I get no error reported by the library at runtime. The zip file is actually created in the specified location, but when I try to open it(i have tried in windows explorer, freecommander and with 7zip) I get the following errors:

error 11002 - Zip file could not be opened
error 11036 - The archive is not a valid Zip archive

I can't immediately see that I am doing anything wrong in the code, is this a bug in the library or can you see something that I have missed.



Function doZip() As String



Dim sourceDir As String = Server.Mappath(".\templates\temp\")



Dim targetName As String = sourceDir & "myzip.zip"



Dim ErrorText As String = "OK"






Using zip As ZipFile = New ZipFile(targetName)



"Readme.txt", "", "Test text")




End Using



Catch ex1 As Exception


ErrorText = ex1.ToString()


End Try



Return ErrorText



End Function


Dec 9, 2008 at 3:14 PM
I had this problem when I first started. When creating a zip file, I found it best to do something like this:

Using zip As ZipFile = New ZipFile()

 zip.AddFileFromString("Readme.txt", "", "Test text")


 End Using

Dec 9, 2008 at 3:22 PM
Hi John,
             Thanks for your quick reply.

I have tried putting the targetname in the zip.save method instead of the constructor as you suggested, but the result is the same. I still get an invalid zip file.
Dec 9, 2008 at 3:59 PM
ok, this is curious. I have just found that I can get a valid zip if I write it out to the Response.Output stream, but not when writing to a file.
Does this throw any light on the problem? I'd much rather have it write to the filesystem.

Dec 9, 2008 at 4:26 PM

I think I have found a workaround so am posting in-case anyone else gets the same problem.

When using the string constructor I got an invalid zip created. This looks to me like it must be a bug in the library.
It looks like the stream constructor works ok, so I modified the code to pass in a filestream like so:



Dim fs As FileStream = File.Create(targetName)



Using zip As ZipFile = New ZipFile(fs)

and it looks to produce a valid zip now.


Dec 9, 2008 at 4:40 PM
It might be a permissions problem. My project for which I use this library is a winforms app and I know asp.net can throw some strange permissions into the mix.

I guess the important thing is that it works. Yeah!
Dec 9, 2008 at 4:49 PM
Thanks John, I think you might be right. It might also be made worse because I'm running Vista as well and everything takes about 3 clicks to approve.
 It's just security gone mad!!