ASP.NET Create zip file for download: the compressed zipped folder is invalid or corrupted

Posted by Jason Braswell on Stack Overflow See other posts from Stack Overflow or by Jason Braswell
Published on 2010-03-16T17:58:23Z Indexed on 2010/03/16 18:01 UTC
Read the original article Hit count: 709

        string fileName = "test.zip";
        string path = "c:\\temp\\";
        string fullPath = path + fileName;
        FileInfo file = new FileInfo(fullPath);

        Response.Clear();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.Buffer = true;
        Response.AppendHeader("content-disposition", "attachment; filename=" + fileName );
        Response.AppendHeader("content-length", file.Length.ToString());
        Response.ContentType = "application/x-compressed";
        Response.TransmitFile(fullPath);
        Response.Flush();
        Response.End();

The actual zip file c:\temp\test.zip is good, valid, whatever you want to call it. When I navigate to the directory c:\temp\ and double-click on the test.zip file; it opens right up.

My problem seems only to be with the download. The code above executes without any issue. A file download dialog is presented. I can chose to either save or open. If I try to open the file from the dialog, or save it and then open it. I get the following dialog message:

The Compressed (zipped) Folder is invalid or corrupted.

For Response.ContentType I've tried:

application/x-compressed application/x-zip-compressed application/x-gzip-compresse application/octet-stream application/zip

The zip file is being created with some prior code (that I'm sure is working fine due to my ability to open the created file directly) using: Ionic.zip

http://www.codeplex.com/DotNetZip

© Stack Overflow or respective owner

Related posts about file-download

Related posts about content-type