C# 从ReportViewer下载PDF
我有一个“下载PDF”按钮,用于呈现ReportViewer并使用Adobe Reader在浏览器中打开它。C# 从ReportViewer下载PDF,c#,pdf,crystal-reports,C#,Pdf,Crystal Reports,我有一个“下载PDF”按钮,用于呈现ReportViewer并使用Adobe Reader在浏览器中打开它。 代码如下: Warning[] warn = null; String[] streamids = null; String mimeType = "application/pdf"; String encoding = String.Empty; String extension = String.Empty; Byte[] byteViewer; byteViewer = repor
代码如下:
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();
但是现在,我想打开一个下载对话框来下载文件,而不是打开pdf。我应该在代码中做哪些更改
@编辑
这个问题的答案太广泛了,我的问题是为了简化下载ReportViewer的过程,同时也为将来可能遇到这个问题的C#程序员提供了参考,无需通过一行行无用的php代码来找到答案。为了简化代码,以供将来可能会发现此问题的StackOverflow用户使用: 在
Response.AddHeader(“内容处置”、“内联;文件名=“+filename+”.pdf”)
,只需将内联
更改为附件
,即可下载文件,而无需在浏览器中打开
这个答案太简单了,为了公平起见,我将检查“社区维基”。重复的可能是php,但php与此无关。标题才是最重要的。你看,在这个问题中有很多行“标题”代码,如果你能简单地说哪一行解决了我的问题,那就太好了……不管怎样,找到了。