views:

214

answers:

2

I'm trying to return a zip file, as a stream over a browser. This works fine with other types of files (e.g. Excel files) but when I start dealing with zip files I can't get my browsers to recognise that it's a zip.

Both Firefox and IE running on my test machine prompt, asking what program to open the file with. Explorer is set as the default for the zip file association.

IE doesn't report very much back, Firefox however tells me what the file type is a

application/zip

which as far as I can tell is the correct mime type for a zip file. The only thing I don't have set is the extension, so the file is just called 'Test' rather than 'Test.zip' but as far as I was aware that should all be figured out by the mime type.

Anyone have any ideas on what might be going wrong?

+2  A: 

You should send the file with, ensuring the file extension is included:

Content-disposition: attachment; filename=Test.zip

As a header.

In C#:

Response.ContentType = "application/zip";
Response.AddHeader("Content-Length", contentLength.ToString());
Response.AddHeader("Content-disposition", "attachment; filename=" + fileName);

if (Request.UserAgent.Contains("MSIE"))
{
    Response.AddHeader("Content-Transfer-Encoding", "binary");
}
John Gietzen
John, thanks for the response. The content type and the content disposition have already been set up but don't work. I'm guessing that the length doesn't make a difference to the type discovered, and because it's effecting firefox too not sure that the transfer encoding is to blame either.
Ian
@Ian: Can you post some code?
John Gietzen
@John: Unfortunately posting the code wasn't really an option because the code is spread through quite a deep hierarchy of classes. You're answer is almost correct. I was missing off the file extension, but also "Content-disposition" should have a lower-case 'd', as it is case sensitive within IE. After those changes it all worked.
Ian
Content-Disposition *should* be upper-cased. If IE doesn't support that, I understand, but: http://www.ietf.org/rfc/rfc2183.txt
John Gietzen
A: 

If you can modify the MIME type, try application/x-zip.

Chris Doggett
I can change the mime type, but application/x-zip is not the ZIP standard.
Ian