【发布时间】: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