Saif
Saif

Reputation: 85

How to make Report Viewer in asp.net open in pdf Direct?

I Have a ReportViewer that is work 100%, but I need it to open in PDF direct

and there is a sample of my code where I'm binding the reportviewer with the data.

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

Upvotes: 1

Views: 3575

Answers (1)

erikscandola
erikscandola

Reputation: 2936

You need to get the byte array that rappresents the PDF file then you need to open a new window with PDF file. Try this:

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();

Upvotes: 2

Related Questions