2013-10-15 27 views
2

我已经在本网站中使用控制台应用程序将.pdf输出的.rdlc渲染为一些文章。对C#.net新建立的应用程序与下面的应用程序相同给出了一个错误,说 : !> Rdclrender.exe Rdclrender.Program.Main(字串[] args = {串[0]})线28 我类如下给出:将RDLC渲染为pdf输出控制台应用程序

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Microsoft.Reporting.WinForms; 


namespace Rdclrender 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      // Variables 
      Warning[] warnings; 
      string[] streamIds; 
      string mimeType = string.Empty; 
      string encoding = string.Empty; 
      string extension = string.Empty; 


      // Setup the report viewer object and get the array of bytes 
      ReportViewer viewer = new ReportViewer(); 
      viewer.ProcessingMode = ProcessingMode.Local; 
      viewer.LocalReport.ReportPath = "Report.rdlc"; 


      byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings); 

      using (System.IO.FileStream fs = new System.IO.FileStream("output.pdf", System.IO.FileMode.Create)) 
      { 
       fs.Write(bytes, 0, bytes.Length); 
      } 
      // Now that you have all the bytes representing the PDF report, buffer it and send it to the client. 
      /* Response.Buffer = true; 
       Response.Clear(); 
       Response.ContentType = mimeType; 
       Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension); 
       Response.BinaryWrite(bytes); // create the file 
       Response.Flush(); // send it to the client to download*/ 
     } 
    } 
} 

这是创建的.rdl PDF的方式?我已经将我的.rdl重命名为手动添加.rdlc项目。

+0

是的,我在WinForms项目中也采用了同样的方式,我们也使用客户端报告。 – Dannydust

+0

@Dannydust你可以弄清楚我提到的错误是什么?我想将报告本地保存到光盘。不能使用报告查看器显示。它应该是一个后台进程。 – flute

+0

你不能调试你的应用程序吗?真的很难说出了什么问题。如果你可以发布一个异常,这将是很好的。但有两个问题:您是否有一个名为“Report.rdlc”的现有报告文件?如果是的话,你可以把完整的路径放在那里。即viewer.LocalReport.ReportPath = @“c:\ myfolder \ Report.rdlc”; – Dannydust

回答

3

好做编程的最简单的解决方法是:

填充一个DataTable与数据报告并命名数据表“销售”(如数据源名称在报表

请注意这一点。是伪代码将无法正常工作,但应该给你一个想法

var myDataSet = new DataSet(); 
var da = new SqlDataAdapter("Select * from Sales", "yourConnectionstring"); 

da.Fill(myDataSet); 
DataTable table = myDataSet.Tables[0]; 
table.TableName = "Sales"; 

为数据源添加数据表到您的报告:

viewer.LocalReport.DataSources.Add(table); 
+0

明白了,但弹出一个不熟悉的错误:error rsInvalidReportDefinition:报告定义无效。详细信息:报告定义具有无法升级的无效目标名称空间“http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition”。 – flute

+0

所以现在你gat一个不同的错误。此错误意味着您的呈现引擎不适合您的报告版本。确保您的报告Dll与报告的版本相匹配。 – Dannydust

+0

例如,我们使用Reporting Dll Version 10.0.0.0和 我们的报告的名称空间为: http://schemas.microsoft.com/sqlserver/reporting/2008/01/reportdefinition – Dannydust

相关问题