如何在pdf Direct中打开asp.net中的报表查看器?

时间:2015-12-31 11:11:07

标签: c# asp.net pdf reportviewer

我有一个100%工作的ReportViewer,但我需要它以PDF直接打开

并且我的代码示例中我将报表查看器与数据绑定在一起。

ReportViewer1.ProcessingMode = ProcessingMode.Local;
ReportDataSource source = new ReportDataSource("dsGetTrnsactions", dt);
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(source);
ReportViewer1.DataBind();
ReportViewer1.LocalReport.Refresh();

1 个答案:

答案 0 :(得分:2)

您需要获取显示PDF文件的字节数组,然后您需要打开一个包含PDF文件的新窗口。试试这个:

byte[] file = ReportViewer1.LocalReport.Render(some parameters);

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "inline;filename=Test.pdf");
Response.Buffer = true;
Response.Clear();
Response.BinaryWrite(file);
Response.End();