Zip file cannot be opened in WinZip

Sep 7, 2009 at 5:27 PM

I'm having an issue with the zip files I generate not being able to be read in WinZip, but they are readable in things like the built in Windows compression tool and WinRAR. The issue was raised by a customer who has to use WinZip due to company guidelines so they cannot change this, so I'm wondering if anyone has the same error.

When the file is downloaded I can open the zip file in Winzip and I can see the files in the folder fine, however when I try and extract them I get the Error: "Warning: skipping FILENAME. The compressed size stored in the local header for this file is not the same as the compressed size stored in the central header."

The code I am using to generate the code is below, as I said it works with other zip programs just not Winzip

string displayFilename = HttpUtility.UrlPathEncode(zipFileName);
Response.AddHeader("Content-disposition", "attachment; filename=" + displayFilename);
Response.ContentType = "application/octet-stream";

Ionic.Zip.ZipFile zipFile = new Ionic.Zip.ZipFile();
foreach (string filePath in filePaths) {
    zipFile.AddFile(filePath, "");
}
zipFile.Save(Response.OutputStream);

Thanks

Coordinator
Sep 7, 2009 at 5:32 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Coordinator
Sep 7, 2009 at 5:35 PM

if it is repeatable, can you upload a zipfile that causes the problem, to this workitem?

A small zipfile is better.

Also, can you show me the rest of your code?  Do you use a using statement?  If not why not?  Where do you call Close() on the ZipFile object?

Can you try it with a using statement and let me know if the problem persists?

Sep 7, 2009 at 5:52 PM

Hi,

Yes it is repeatable, however I can't upload a file at the moment as the data is confidential, I'll try and reproduce the error using some dummy data. The issue appears to happen when the files in the zip file are within a directory, for example:

Folder\test.txt - Causes an error

test.txt - Doesn't cause an error

No I'm not calling close() on the ZipFile object as there isn't a method in the API to call there, should I be calling close() on the Response.OutputStream after I've called save()?

As for using statement I never use them, I just use the foreach Iterator for the filenames, heres the full method of the code:

/// <summary>
        /// Puts all the files in the list provided into a zip file, and then streams it to the HTTP Response
        /// </summary>
        /// <param name="zipFileName">The name of the zip file</param>
        /// <param name="filePaths">A list of absolute file paths</param>
        protected void StreamFilesIntoZipFile(string zipFileName, List<string> filePaths) {
            string displayFilename = HttpUtility.UrlPathEncode(zipFileName);
            Response.AddHeader("Content-disposition", "attachment; filename=" + displayFilename);
            Response.ContentType = "application/octet-stream";

            Ionic.Zip.ZipFile zipFile = new Ionic.Zip.ZipFile();
            foreach (string filePath in filePaths) {
                zipFile.AddFile(filePath, "");
            }
            zipFile.Save(Response.OutputStream);
            Response.Close();
        }

Coordinator
Sep 7, 2009 at 6:24 PM
Edited Sep 7, 2009 at 8:17 PM

Whoops - what I meant was Dispose().  you need to call Dispose(), not Close().

The using statement is not optional. Either use it or call ZipFile.Dispose().