2013-09-25 124 views
0

我已經創建了一個RDLC報告,當我在顯示網頁瀏覽器中它正常工作。但我的客戶現在希望我發送PDF文件到瀏覽器/客戶端,而不是在Web瀏覽器中顯示報告。當我添加代碼來創建報告的PDF並將其發送到客戶端/瀏覽器時,出現錯誤。 這裏是我的代碼發送PDF到客戶端/瀏覽器:RDLC報告錯誤:Microsoft.ReportingServices.ReportProcessing.ReportProcessingException

<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> 

我頁面加載後面調用此代碼:

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報告中有一個名爲「數據集1」數據集。 錯誤截圖: enter image description here

回答

2

爲「數據集1」的例子提供任何其他的名字:「MyDataSourceName」和數據源「StudentList」這是我的數據源轉換爲列出

ReportDataSource rds = new ReportDataSource("MyDataSourceName", StudentList); 

更多信息:http://forums.asp.net/t/1556522.aspx