FireFox cannot download zip file from ASP.NET

Hi Experts,

I am using ASP.NET Response.Write to transfer a file to the browser. In IE, whatever the ContentType I set in Response, it works fine. However in Firefox, I got following error (see the screenshot). I understand that the firefox is following the HTTP standard that I have to specfy the content type. Actually I already do. The zip file cannot be recognized by firefox but the other file types work fine (xls, doc, ppt). Does anybody know what happened and how to solve the issue?

This is what I get from the Internet:
"Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource."

I am using firefox 3.5.6. Any help will be appreciated. Thanks in advance!
void foo()
{
                 //Zip all the files
                 Response.ContentType = "application/x-zip-compressed";
                 string filepath = AxImageFileCacheMgr.CreateZipPackage(sess, "ProtectedFiles.Zip", _docCtx.IRMRenderPaths);
                 using (System.IO.Stream outStream = XtenderSolutions.Utility.IO.File.Open(filepath, Global.Config, sess.Credentials))
                 {
                    Response.Charset = "65001";
                    string downloadFileName = HttpUtility.UrlEncode(String.Format("{0}.zip", docIndexes[0]));
                    Response.AddHeader("Content-Disposition", "attachment;Filename=\"" + downloadFileName + "\"");
                    WriteStream(outStream, true);
                 }
}            

      public static string CreateZipPackage(CMSession sess, string mainFileName, string[] fileNames)
      {
          string packagePath = null;
          WindowsImpersonationContext wic = null;
          TempFileCache tempCache = new TempFileCache();
          UncConfig cachePath = TempFileCache.CachePath;
          wic = cachePath.Authentication.Impersonate(sess.Credentials);
          string zipfileName = mainFileName + ".ZIPpackage";
          packagePath = tempCache.FileFullName(zipfileName);
          using (Package package = Package.Open(packagePath, FileMode.Create))
          {
              foreach (string file in fileNames)
              {
                  string fileName = System.IO.Path.GetFileName(file);
                  string extension = System.IO.Path.GetExtension(file);
                  Uri partUri = PackUriHelper.CreatePartUri(new Uri(fileName, UriKind.Relative));
                  // Add the file as a part to the Package
                  PackagePart packageFile = package.CreatePart(partUri, GetMimeString(extension));
                  // Copy the data to the Document Part
                  using (FileStream inputFileStream = new FileStream(file, FileMode.Open, FileAccess.Read))
                  {
                      WriteStream(inputFileStream, packageFile.GetStream());
                  }
              }
          }
		  return packagePath;
      }

Open in new window

ScreenshotFireFox.JPG
LVL 9
magicdlfAsked:
Who is Participating?
 
magicdlfAuthor Commented:
0
 
ICaldwellCommented:
change this part of your code
void foo()
{
                 //Zip all the files
                 string filepath = AxImageFileCacheMgr.CreateZipPackage(sess, "ProtectedFiles.Zip", _docCtx.IRMRenderPaths);
                 Response.AddHeader("Content-Disposition", "attachment;Filename=" + downloadFileName);
                 Response.ContentType = "application/octet-stream";
                 Response.Flush();
                 using (System.IO.Stream outStream = XtenderSolutions.Utility.IO.File.Open(filepath, Global.Config, sess.Credentials))
                 {
                    string downloadFileName = HttpUtility.UrlEncode(String.Format("{0}.zip", docIndexes[0]));
                    WriteStream(outStream, true);
                 }
                 Response.End;
}  

Open in new window

0
 
ICaldwellCommented:
oops, also add the Response.Charset
void foo()
{
                 //Zip all the files
                 string filepath = AxImageFileCacheMgr.CreateZipPackage(sess, "ProtectedFiles.Zip", _docCtx.IRMRenderPaths);
                 Response.AddHeader("Content-Disposition", "attachment;Filename=" + downloadFileName);
                 Response.ContentType = "application/octet-stream";
                 Response.Charset = "65001";
                 Response.Flush();
                 using (System.IO.Stream outStream = XtenderSolutions.Utility.IO.File.Open(filepath, Global.Config, sess.Credentials))
                 {
                    string downloadFileName = HttpUtility.UrlEncode(String.Format("{0}.zip", docIndexes[0]));
                    WriteStream(outStream, true);
                 }
                 Response.End;
}  

Open in new window

0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
magicdlfAuthor Commented:
Hi ICaldwell,
Thanks for your advice, actually the octet-stream is the first thing I have tried. I am trying your code now, any other idea?

Btw, here's my response header (I changed the content type to application/binary, still not working):
HTTP/1.1 200 OK
Server: Microsoft-IIS/5.1
Date: Wed, 30 Dec 2009 05:36:01 GMT
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
Content-Disposition: attachment;Filename="PDF.zip"
Cache-Control: private
Content-Type: application/binary; charset=UTF-8
Content-Length: 434594
0
 
magicdlfAuthor Commented:
In the WriteStream, the response header will be flushed at the first time.  I don't need to worry about that.
0
 
zadeveloperCommented:
Tested working in Firefox  3.5.6
 

void DownloadZipFile(string zipData, string fileName) 
{ 
Response.ContentType = "application/zip"; 
Response.AddHeader("Content-Disposition", "attachment;Filename=\"" + fileName + "\""); 
Response.Clear(); 
Response.ContentType = "application/zip"; 
Response.AddHeader("Content-Disposition", "inline; filename=" + fileName); 
var streamData = Encoding.ASCII.GetBytes(zipData); 
Response.OutputStream.Write(streamData, 0, streamData.Length); 
Response.End(); 
}

Open in new window

0
 
zadeveloperCommented:
sorry - left some test stuff in there, lets try this again :)
private void DownloadZipFile(string zipData, string fileName)
    {
        Response.Clear();
        Response.ContentType = "application/zip";
        Response.AddHeader("Content-Disposition", "inline; filename=" + fileName);

        var streamData = Encoding.ASCII.GetBytes(zipData);

        Response.OutputStream.Write(streamData, 0, streamData.Length);
        Response.End();
    }

Open in new window

0
 
zadeveloperCommented:
any solution on this question ?
0
 
zadeveloperCommented:
Did this work for you ?
0
 
magicdlfAuthor Commented:
Sorry, your code is just a sample but I am still stucking with the real problem. I am trying to find out the solution. Once I get it I will post it here and let you know. Thanks for replying.
0
 
zadeveloperCommented:
np.

Buti did test my code on firefox and it downloads the files perfectly.
0
 
magicdlfAuthor Commented:
Here's an update. It ONLY happens when I tried to download a zip from modaldialog. I think you will be easily to reproduce this. Any idea?
I use this to open a modal dialog in firefox 3.5.6. The window should be modal. I don't know if there is any alternatives.
    window.showModalDialog(url, window, "dialogWidth:500px;dialogHeight:550px;resizable:no;scroll:yes;status:yes;title:no;menu:no;toolbar:no");
0
 
zadeveloperCommented:
Hi magicdlf:
Any chance you could post the solution here so we know what the issue was?
0
 
magicdlfAuthor Commented:
I already posted. See me last posts.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.