views:

316

answers:

3

I have a friend experiencing problems testing a web site of mine that provides a CSV export for a report. He says the CSV is output to the screen, and no file is created.

It works fine on my IIS7, Vista, and IE7 setup. I can't get more details at the moment, but I'd like to at least ask: is my code, below, for sending the CSV adequate to be browser/version independent?

    Response.Clear();
    Response.Buffer = true;
    Response.ContentType = "text/csv";
    string fileName = GetExportFileName();
    Response.AddHeader("Content-Disposition", "filename=" + fileName);
    dt.WriteCsv(Response.Output, false);
    Response.End();

I'm building fileName to include a date with / separators, which may be causing a problem, but it doesn't affect my machine, and the / gets automagically replaced with _.

+1  A: 

I have also used

Response.AddHeader("content-disposition", "attachment;filename=FileName.csv");

which adds the "attachment" text. You might try that to see if it makes any difference for your friend.

DOK
A: 

The only sure fire way to get IE to prompt for a download is to have the CSV file compressed (ie file.csv.zip or file.zip).

See

No HTTP header will force IE6 to offer a download. This is especially true for text content, which is 'auto-detected' by IE.

You can try with Content-Disposition attachment; filename=file.csv but I'm not certain it'll always work. If it does, please confirm.

Vinko Vrsalovic
A: 

There is a known problem in IE6 that do not correctly support the content-disposition meta tag and there are some gotchas in how to compose the various meta tags.

This link from Scott Hanselman details everything about the issue.

Regards Massimo

massimogentilini