views:

17

answers:

1

Hi

I have a webpage called DisplayBinaryData.aspx - the purpose of this page being to display/download any word, excel, pdf or images. I call this webpage and pass the id of my BinaryData entity using a querystring. The BinaryData entity contains the file, filename and contenttype uploaded using the asp.net fileUploadControl. The code in the page load is below:

    BinaryData obj = GetBinaryObjectById(int.Parse(Request.QueryString["id"]));

    Response.Clear();

    Response.BufferOutput = true;

    Response.AddHeader("Content-Disposition", "attachment; filename=" + obj.FileName);

    Response.ContentType = obj.FileContentType;

    Response.BinaryWrite(obj.BinaryFile);

    Response.Flush();

    Response.Close();

    Response.End();

This code executes perfect in IE,but fails when executed in FireFox. IE prompts the user, either to save or open the content. FireFox also prompts the user, but the dialog box fails to save or open any content. When executing this in google chrome - there is no dialog box, it starts downloading the content automatically.

My question: I need this code to be compatable with FireFox - any suggestions?

A: 

The behavior you mention with Chrome is just do to the default settings for Chrome. You can change those by going to the "Under the hood" tab of the Options window. Then select the "Ask Where to save each file before downloading" checkbox.

Does your obj.FileName have a space in the name? See this post on "Content Disposition" in different browsers.

Content Disposition in different browsers

Today I had to resolve an issue where in different browsers the filed dynamically generated download worked very differently / at all

The setup, we had an xml file with a custom extension, say .mj, which was being served up by ASP. The HTTP Header had a content disposition header and a response type set.

Response.AddHeader "Content-Disposition", "attachment; filename=""our file.mj"""
Response.ContentType = "text/xml"

This worked fine in Internet Explorer, the file was downloaded as "our file.mj". However FireFox and Chrome acted very differently, in FireFox the file was downloaded as just "our", and Chrome as "our file.xml". In FireFox it appears that the issue is caused by having a space in the file name, this forum post by funkdaddu helped me on this, so by removing the space FireFox could now download the file as "ourfile.mj". ...

David Glass