After creating .zip I get error when opening the file

Aug 24, 2011 at 7:31 PM

After I create the zip file using this code.

Using zip = New ZipFile()

For Each row As GridDataItem In RadGridDocs.MasterTableView.Items

Dim clientSelectColumn As CheckBox = DirectCast(row("ClientSelectColumn").Controls(0), CheckBox)

Dim chkBox = clientSelectColumn.Checked

If chkBox = "True" Then

Dim txtDocument As TextBox = row.FindControl("txtDocumentFileName")
Dim fileName As String = txtDocument.Text

Dim txtDocumentPath As TextBox = row.FindControl("txtDocumentPath")
Dim documentPath As String = txtDocumentPath.Text

Dim fullpath As String = Server.MapPath("~") + "\" + documentPath + fileName

fullpath = Replace(fullpath, "/", "\")

fullpath = Replace(fullpath, "\", "\\")

'Code to Zip a Folder.

zip.AddFile(fullpath)

End If

Next

zip.Save(Response.OutputStream)

End Using


---------------------------------------------------------------------

I am trying to send this out via a asp.net application using .NET 3.5. I keep getting the error "Cannot open file: it does not appear to be a valid archive."

Are there any ideas?

Coordinator
Aug 24, 2011 at 10:04 PM

That error indicates that the thing you are trying to read is not a valid zip file. Usually this means a truncated file, or a file with extra rubbish in it, after the valid zip bytes. Either is possible with ASPNET.

The most common case in my experience is rubbish after the valid zip data.  After you call Zip.Save(Response.OutputStream), you need to call Response.End() in order to terminate the ASPNET response, flush the output stream, and transmit the file and only the zip file, to the browser.  did you do that?  If your app does not do that, it can result in rubbish in the downloaded (transmitted) zip file.

If you want to look more closely into the problem, you can hook up Fiddler2 to see the HTTP transaction.  Or, open the resulting downloaded zipfile itself in an editor that supports editing binary files, like emacs. If you see rubbish HTML codes either in the top of the file or the bottom of the zip file, then you probably have a buffer problem on the Response.OutputStream.  You need to clear the buffer and reset the mimetype before writing anything, and call Response.End() after ZipFile.Save(Response.OutputStream) .   Complicating matters is that I Released a faulty example a looong time ago that did not call Response.End() as it needed to, and it has been re-used in lots of places.  You may have been following a bad example.

The problem is not in the code you are showing above.  It is in code that runs before that, or after that.

Aug 25, 2011 at 12:59 PM
Thanks,

That seems to be helping me I really appreciate your help.

______________________________
Thank You,

Charles Hawk
IS Specialist

Kawasaki Motors Manufacturing Corp., USA
P.O. Box 81469, 6500 N.W. 27th Street
Lincoln, NE 68524

Phone: (402) 476-6600 x5357
Fax: (402) 476-4372

(This E-mail address is to be used for business purposes only. Do not send any E-mail messages to this address that do not have a specific business purpose. Thank you.)



From: "Cheeso" <notifications@codeplex.com>
To: chawk@lcn.kmmfg.com
Date: 08/24/2011 05:04 PM
Subject: Re: After creating .zip I get error when opening the file [DotNetZip:270266]




From: Cheeso

That error indicates that the thing you are trying to read is not a valid zip file. Usually this means a truncated file, or a file with extra rubbish in it, after the valid zip bytes. Either is possible with ASPNET.

The most common case in my experience is rubbish after the valid zip data. After you call Zip.Save(Response.OutputStream), you need to call Response.End() in order to terminate the ASPNET response, flush the output stream, and transmit the file and only the zip file, to the browser. did you do that? If your app does not do that, it can result in rubbish in the downloaded (transmitted) zip file.

If you want to look more closely into the problem, you can hook up Fiddler2 to see the HTTP transaction. Or, open the resulting downloaded zipfile itself in an editor that supports editing binary files, like emacs. If you see rubbish HTML codes either in the top of the file or the bottom of the zip file, then you probably have a buffer problem on the Response.OutputStream. You need to clear the buffer and reset the mimetype before writing anything, and call Response.End() after ZipFile.Save(Response.OutputStream) . Complicating matters is that I Released a faulty example a looong time ago that did not call Response.End() as it needed to, and it has been re-used in lots of places. You may have been following a bad example.

The problem is not in the code you are showing above. It is in code that runs before that, or after that.

Read the full discussion online.

To add a post to this discussion, reply to this email (DotNetZip@discussions.codeplex.com)

To start a new discussion for this project, email DotNetZip@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on CodePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at CodePlex.com