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, no matter what you want to name. When I go to the c: \ temp \ directory and double-click the test.zip file; he opens up.
My problem seems to be related only to the download. The above code is no problem. The file upload dialog is presented. I can choose to save or open. If I try to open a file from a dialog or save it, then open. I get the following dialog box:
A compressed (encoded) folder is invalid or damaged.
For Response.ContentType I tried:
application / x-compressed application / x-zipper compressed application / x-GZIP-compresse Application / octet stream Application / mail
A zip file is created with some previous code (I'm sure it works fine due to my ability to directly open the created file) with: Ionic.zip
http://www.codeplex.com/DotNetZip
source share