views:

135

answers:

4

The following headers work on IE but not on FF

<%@ Page Language="C#" ContentType="text/csv" Inherits="System.Web.Mvc.ViewPage"%>
<% Response.AddHeader("Content-Disposition", "filename=report.csv;attachment"); %>

In FF the suggested name in FF appears as "report" without the extension.

A: 

try "attachment; filename=\"report.csv\"" (i.e. with quoted filename)

devio
+4  A: 

filename is just an parameter of Content-Dispostion. So you have to swap both:

<% Response.AddHeader("Content-Disposition", "attachment;filename=report.csv"); %>
Gumbo
A: 

This question about CSV generation helped me when I needed to implement CSV generation and download: How do I best generate a CSV (comma-delimited text file) for download with ASP.NET?

Michaël Larouche
+1  A: 

I am currently using code that looks like this:

response.AddHeader("Content-Disposition", "attachment; filename=\"data.csv\"");

In my daily work - and that works just fine. Also are you sure this is not your OS or anything that has the "Hide extensions for known file types"-option enabled? (I know Windows have this option and it drives me crazy)

kastermester
Why people voted up only the older member?
Jader Dias
Maybe because he linked the documentation
Jader Dias
Possibly, idk... I *think* the solution is to use the quotes (being escaped) but I honestly don't know - I posted this as I knew it worked for me, I have no link to documentation or anything as it is code I created months and months ago and have used ever since without any issues.
kastermester