【问题标题】:Rendering RDLC to pdf output console application将 RDLC 渲染到 pdf 输出控制台应用程序
【发布时间】:2013-10-15 05:31:55
【问题描述】:

我在本网站上引用了一些文章,用于使用控制台应用程序将 .rdlc 渲染为 .pdf 输出。我是 C# 的新手,.net 构建了一个与以下相同的应用程序给出了一个错误提示 :>Rdclrender.exe!Rdclrender.Program.Main(string[] args = {string[0]}) 第 28 行 我的课程如下:

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 并将 .rdlc 项目添加到项目中。

【问题讨论】:

  • 是的,我在 WinForms 项目中也是这样做的,我们也使用客户端报告。
  • @Dannydust 你能弄清楚我提到的错误是什么吗?我想将报告本地保存到光盘。不要使用报告查看器显示。它应该是一个后台进程。
  • 你不能调试你的应用程序吗?真的很难说出了什么问题。如果您可以发布异常,那就太好了。但是有两个问题:您是否有一个名为“Report.rdlc”的现有报告文件?如果是的话,你能把完整的路径放在那里吗? e. viewer.LocalReport.ReportPath = @"c:\myfolder\Report.rdlc";
  • 是的完整路径已经给出。我尝试调试,异常是“本地处理异常未处理”
  • 好的,然后检查内部异常,使用此技术时很难找到错误。仔细检查所有异常信息。也许还有更多的信息。请检查查看器控件的 LocalReport 属性。

标签: c# reporting-services console-application rdlc rdl


【解决方案1】:

好的,以编程方式进行,最简单的解决方案是:

用报表的数据填充 DataTable 并将 Datatable 命名为“Sales”(就像报表中的 DataSource 名称一样。

请注意这是伪代码,它不会工作,但应该给你一个想法。

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

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

将 DataTable 作为数据源添加到您的报告中:

viewer.LocalReport.DataSources.Add(table);

【讨论】:

  • 知道了,但弹出一个不熟悉的错误:error rsInvalidReportDefinition:报告定义无效。详细信息:报告定义的目标命名空间“schemas.microsoft.com/sqlserver/reporting/2010/01/…”无效,无法升级。
  • 所以现在你遇到了另一个错误。此错误意味着您的渲染引擎不适合您的报告版本。确保您的报告 Dll 与您的报告版本匹配。
  • 例如,我们使用的是报告 Dll 版本 10.0.0.0,我们报告的命名空间是:schemas.microsoft.com/sqlserver/reporting/2008/01/…
  • 我的意思是您的 ReportViewer DLL (Microsoft.ReportViewer.Common)。我也在使用VS2008,DLL的版本是10.0.0.0
  • 您删除引用并重新添加。当您查找 dll 时,它应该已经存在于不同的版本中。所以你应该取最大的版本号,因为你的报告版本是 2010/01,我的是 2008/01。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-30
  • 1970-01-01
  • 2011-03-10
  • 1970-01-01
  • 2010-09-14
  • 2019-03-22
相关资源
最近更新 更多