简体   繁体   中英

Download PDF from ReportViewer

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM