haf / DotNetZip.Semverd

Please use System.IO.Compression! A fork of the DotNetZip project without signing with a solution that compiles cleanly. This project aims to follow semver to avoid versioning conflicts. DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files.
Other
546 stars 218 forks source link

Extra Characters in DotNetZip archive files #229

Open jruggiero1955 opened 3 years ago

jruggiero1955 commented 3 years ago

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 butDownloadClick(object sender, EventArgs e) { string strShortFileName; string strLongFileName; WebRequest wReq; WebResponse wResp; Stream receiveStream; string zipName; lblErrorText.Text = ""; try { using (ZipFile zip = new ZipFile()) { zip.AlternateEncodingUsage = ZipOption.AsNecessary; Response.Clear(); 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.Clear();
                    Response.BufferOutput = false;
                    Response.ContentType = "application/zip";
                    Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
                    zip.Save(Response.OutputStream);
                    HttpContext.Current.ApplicationInstance.CompleteRequest();
                    Response.Clear();
                }
                else
                    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");
        }
    }

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