I have created an RDLC report and it works fine when I show the it in web browser. But my client now wants me to send PDF file to the browser/client instead of showing the report in web browser. I'm getting error when I added the code behind to create and send the report's PDF to the client/browser. Here is my code to send PDF to the client/browser:
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetData"
TypeName="CourrierExpress.ExpressCourierDataSetTableAdapters.uspFrontEnd_Invoice_PrintInvoiceTableAdapter"
OldValuesParameterFormatString="original_{0}">
<SelectParameters>
<asp:QueryStringParameter Name="InvoiceId" QueryStringField="InvoiceId" Type="Int64"
DefaultValue="" />
</SelectParameters>
</asp:ObjectDataSource>
I'm calling this code behind on Page Load:
Int64 invoiceId = int.Parse(Request.QueryString["InvoiceId"]);
Warning[] warnings;
string[] streamIds;
string mimeType;
string encoding;
string extension;
var rds = new ReportDataSource { DataSourceId = "ObjectDataSource1", Name = "DataSet1" };
var viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.DataSources.Clear();
viewer.LocalReport.ReportPath = "Reports/ReportInvoicePrint.rdlc"; //This is your rdlc name.
viewer.LocalReport.DataSources.Add(rds);
var bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension,
out streamIds, out warnings);
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename= filename" + "." + extension);
Response.OutputStream.Write(bytes, 0, bytes.Length); // create the file
Response.Flush(); // send it to the client to download
Response.End();
RDLC report has Dataset named "DataSet1".
Error screenshot is:
