0

All,

In my application i allow users to download a csv file from the App. When a user clicks on the Download file link , they see the Download file dialog box. My problem is that some o f the files opens as an HTML document.This happens intermittently.This is the code am using.Can anyone please help?

Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = "application/octet-stream"; 
Response.AppendHeader("Content-Disposition"
  , "attachment; filename=" + sf.FileName);
Response.OutputStream.Write(sf.Data, 0, sf.Data.Length);
Response.Flush();
Response.Close();

I tried Response.End() insted of Response.Flush(); but didnt help.

Any help would be greatly appreciated

THanks

RJ

rene
  • 41,474
  • 78
  • 114
  • 152
RJT
  • 5
  • 5
  • Please indent your code with four spaces and use normal formatting and newlines. – SLaks Mar 01 '11 at 16:21
  • Forget about what you think you're doing - what headers actually get sent back? Use Firefox's Live HTTP Headers or the net tab in firebug to find out. – Stefan Kendall Mar 01 '11 at 16:24

1 Answers1

2

text/csv is more appropriate.

see: Response Content type as CSV

Community
  • 1
  • 1
John Sobolewski
  • 4,512
  • 1
  • 20
  • 26