Corrupted Zip File after download

Jul 28, 2010 at 10:42 PM

Hello,

 

I have some users complaining that they receive a "file is corrupt" error when they open a zip file that has been zipped and downloaded. I have not been able to reproduce this issue. Was wondering if someone may check my code to see if I have something that is causing the issue?

Thanks,

 

void MyButton_Click(Object source, EventArgs e)
{
	Server.ScriptTimeout = 3600000;
    TreeNodeCollection checkedNodes = MyTree.CheckedNodes;
    MyDataList.DataSource = checkedNodes;
    MyDataList.DataBind();

    Response.Clear();
	Response.BufferOutput = false;  
    String sMappedPath = Request.MapPath("users");
  Path.GetFileName(file);
    System.Web.HttpContext c = System.Web.HttpContext.Current;
    String ReadmeText = String.Format("This is a zip file that was dynamically generated at Spencebothers.com on {0}\n The files that you checked are included in this zip file.",
                                     System.DateTime.Now.ToString("G"),
                                     System.Environment.MachineName,
                                     c.Request.ServerVariables["SERVER_SOFTWARE"]
                                     );
    string archiveName = String.Format("SpenceBrothers-{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
    Response.ContentType = "application/zip";
    Response.AddHeader("content-disposition", "filename=" + archiveName);
    
    
    
    using (ZipFile zip = new ZipFile())
    {
        foreach (TreeNode node in MyTree.CheckedNodes)
        {
        
		if (node.Value.Contains(".") == false)
		{
                            zip.AddDirectory(System.IO.Path.Combine(sMappedPath, node.Value.Replace("~/users/", "")),node.Text);
			}
			else if (node.Value.Contains(".") == true)
			{
                zip.AddFile(System.IO.Path.Combine(sMappedPath, node.Value), "");
			}

        }
        
        zip.AddEntry("Readme.txt", ReadmeText);
        zip.Save(Response.OutputStream);
    }
    Response.End();

    
}

Coordinator
Jul 29, 2010 at 12:02 PM
I've seen this kind of thing before, particularly on Mac clients. The zip app on Mac apparently has problems with bit 3 encoding. There was a thread of about 100 messages covering this; search the archives of this forum for details. There are workarounds and explanations. Also Ive heard there is a browser cache corruption issue on some older versions of IE. This is unrelated to DotNetZip, but as I remember it did specifically relate to zip files. Try searching other forums for info on that. You'll have to do some research on your end about when and where the problem happens, to narrow things down. It might also help to retain the corrupted zipfile itself, so you can figure out just what is wrong with it.
Aug 30, 2010 at 10:07 AM

For me zip files are very important. And once something happened with some of them. Fortunately I stumbled upon a nice utility - corrupt winzip file. To my great surprise, it restored theirs within a minute and utterly simply.