I need to stream a file to the Response for saving on the end user's machine. The file is plain text, so what content type can I use to prevent the text being displayed in the browser?
+1
A:
I don't think it works that way.
Use a Content-Disposition: attachment
header, but stick with the correct Content-Type.
Tomalak
2008-10-09 11:43:15
+11
A:
In most cases, the following should work:
Content-type: application/octet-stream
Content-Disposition: attachment; filename="myfile.txt"
There are some marginal cases of browsers that will still display it as a text file, but none of the mainstream browsers will (I'm talking about browsers embedded in some MIDs).
Andrew Moore
2008-10-09 11:43:30
Do you need to lie about the Content-type? Would be nicer if you could just use Content-Disposition, which /should/ work.
Bobby Jack
2008-10-09 11:55:46
In my experience, application/octet-stream makes it work more reliably across all browsers.
ceejayoz
2008-10-09 12:01:57
^ What he said. Internet Explorer 6 may still display it as text if text/plain is used.
Andrew Moore
2008-10-09 12:04:30
A:
Here is a list of ASP.net examples. It is most reliable with both an application/octet-stream content type and a content-disposition header of 'attachment'.
ceejayoz
2008-10-09 11:44:54
+2
A:
To be on the safe side and ensure consistent behavior in all browsers, it's usually better to use both:
Content-Type: application/octet-stream
Content-Disposition: attachment;filename=\"My Text File.txt\"
Mun
2008-10-09 11:51:36