1

I have a memory stream where I put the value of my PDF document.

my code is (in asp.net) will open a page in the browser containing the pdf content. what i want is download the pdf document instead of openning it during the browser

this is my code

// Send PDF to browser

MemoryStream stream = new MemoryStream();

document.Save(stream, false);

Response.Clear();

Response.ContentType = "application/pdf";

Response.AddHeader("content-length", stream.Length.ToString());

Response.BinaryWrite(stream.ToArray());
Response.Flush();

stream.Close();

Response.End();

can u help me?

Uwe Keim
  • 38,279
  • 56
  • 171
  • 280
Marco Dinatsoli
  • 9,834
  • 34
  • 124
  • 238
  • http://stackoverflow.com/questions/3889521/response-addheadercontent-disposition-not-opening-file-in-ie6 – Eser Aug 23 '15 at 10:06
  • 2
    [Do the google](http://stackoverflow.com/questions/9195304/how-to-use-content-disposition-for-force-a-file-to-download-to-the-hard-drive)! – Uwe Keim Aug 23 '15 at 10:07

1 Answers1

2

Just add the Content-Disposition header with attachment flag:

Response.AddHeader("content-disposition", "attachment; filename=foo.pdf");
Darin Dimitrov
  • 994,864
  • 265
  • 3,241
  • 2,902