Click here to Skip to main content
15,441,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to use DotNetZip in a C# ASP.NET web page to create a archive file containing multiple graphic images. I present a list of file names in a repeater. The user selects one or more files from the repeater. The code then locates the files on a different server, creates a zipfile from them and then downloads them. The file is created, but I cannot open or extract files from it using native Win10. I have to use 7-Zip to use the file.

When I open the file using 7-Zip I see this warning when I use the Info button: There are some data after the end of the payload data.

The following is the code I use. Again, I get the files from a repeater on the web page:

protected void butDownload_Click(object sender, EventArgs e)
            string strShortFileName;
            string strLongFileName;
            WebRequest wReq;
            WebResponse wResp;
            Stream receiveStream;
            string zipName;
            lblErrorText.Text = "";
                using (ZipFile zip = new ZipFile())
                    zip.AlternateEncodingUsage = ZipOption.AsNecessary;
                    Response.BufferOutput = false;
                    zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
                    foreach (RepeaterItem ri in rptConMedia.Items)
                        if (((CheckBox)ri.FindControl("chkBoxDownload")).Checked)
                            strShortFileName = ((Label)ri.FindControl("lblFileName")).Text;
                            strLongFileName = ((Label)ri.FindControl("lblPath")).Text + strShortFileName;
                            wReq = WebRequest.Create(strLongFileName);
                            wResp = wReq.GetResponse();
                            receiveStream = wResp.GetResponseStream();
                            zip.AddEntry(strShortFileName, receiveStream);
                        // add the report into a different directory in the archive
                    if (zip.Count > 0)

                        Response.BufferOutput = false;
                        Response.ContentType = "application/zip";
                        Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
                        lblErrorText.Text = "You must select at least one file to download.";
            catch (Exception ex)
                lblErrorText.Text = ex.Message;
                MFAErrorUtil.LogError(ex, CMConstants.ErrorLogPath, "wucConMediaDisplay:Zip");

What I have tried:

If I download to a file on the IIS server instead of using the web browser, the zip file has no problems.

I've tried using different properties and methods on the Response class (Buffer, BufferOutput, Clear, Flush, ContentEncoding) with no success.

Any guidance with this would be appreciated

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900