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
  • 39,551
  • 56
  • 175
  • 291
Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253
  • 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
  • 1,023,142
  • 271
  • 3,287
  • 2,928