0

I have a "Download PDF" button that render a ReportViewer and open it in browser using Adobe Reader.
Here's the code:

Warning[] warn = null;
String[] streamids = null;
String mimeType = "application/pdf";
String encoding = String.Empty;
String extension = String.Empty;
Byte[] byteViewer;
byteViewer = report.LocalReport.Render("pdf", null, out mimeType, out encoding, out extension, out streamids, out warn);
Response.Buffer = true;
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline; filename=" + fileName + ".pdf");
Response.BinaryWrite(byteViewer);
Response.Flush();
Response.End();

But now, instead of opening the pdf, i want to open a download dialog to download the file. What changes in the code should I do?

@edit The answers in that question are way too extensive, my question was asked to simplify the process of downloading a ReportViewer, and also adding a reference for future C# programmers that may encounter this question, without having to dig through lines of useless php code to find the answer.

Lucas
  • 534
  • 1
  • 10
  • 29
  • possible duplicate of [HTTP Headers for File Downloads](http://stackoverflow.com/questions/386845/http-headers-for-file-downloads) – Marc B Sep 02 '15 at 18:51
  • that dupe is for php, but the php is irrelevant. the headers are what matters. – Marc B Sep 02 '15 at 18:51
  • you see in that question there's many lines of "header" code, if you could simply say which one solves my problem, that would be great... – Lucas Sep 02 '15 at 18:59
  • nevermind, found it. – Lucas Sep 02 '15 at 19:02

1 Answers1

0

To simplify the code for future StackOverflow users that may find this question:

in Response.AddHeader("content-disposition", "inline; filename=" + fileName + ".pdf");, just change inline to attachment, and that will download the file instead of opening in the browser.

This answer is too simple, so I will check "community wiki" to be fair.

Lucas
  • 534
  • 1
  • 10
  • 29