2017-03-08 94 views
0

我试图在C#中使用报告工作。我试图嵌入我的RDLC文件,例如:处理“非法路径”中的C#报告错误

var reportDataSource = new ReportDataSource("ProspectsDataSet", _allProspects); 
ReportViewer.LocalReport.DataSources.Add(reportDataSource); 

ReportViewer.LocalReport.ReportEmbeddedResource = "SdcDatabase.Modules.EnquiryModule.View.Reports.ProspectsReport.rdlc"; 
ReportViewer.ZoomMode = ZoomMode.PageWidth; 
ReportViewer.RefreshReport(); 

在RDLC文件本身的生成操作设置为嵌入的资源,并复制到输出目录设置为始终复制。

我有双重检查,我敢肯定,这是ReportEmbeddedResource字符串中的正确命名空间。然而,当我尝试加载的报告中,我得到这个错误:

enter image description here

我曾尝试在路径切换周围的几件事情,如更换“”与'/'和'\',但到目前为止我还没有能够得到任何解决这个问题。我也尝试使用LocalPath而不是EmbeddedResource,但我又遇到了错误。

我已经搜索了这个问题,但到目前为止还没有找到任何解决我的问题。

+0

https://social.msdn.microsoft.com/Forums/zh-CN/7b259014-9bb2-424a-9c5b-37be2fcb1bef/how-to-use-reportembeddedresource-in-reportviewer-webform-control?forum=vsreportcontrols – mm8

回答

0

我有一个报告包装类,适用于我的应用程序。我有一个属性来保存我想运行的“.rdlc”报告定义的名称。然后,当我调用我的“RunReport()”方法时,我根据从应用程序程序集资源中读取流来分配报告。你有什么短的版本可能

ReportViewer.LocalReport.LoadReportDefinition(GetRDLCStream("ProspectsReport.rdlc")); 

然后,下,我有一个方法

private Stream GetRDLCStream(string rptRDLC) 
{ 
    var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
        "SdcDatabase.Modules.EnquiryModule.View.Reports." + rptRDLC); 

    return stream; 
} 

很显然,我不是正面的路径的命名约定到您的项目,但我暗示上述路径。然而,它应该反映(例如)

"NameOfYourApp.SubFolderWithinPath.MaybeReportsSubFolder." + actualReport.RDLC name 

这样一来,我从来没有担心复制出来的资源,希望的路径工作。我知道它是嵌入式的,也是组装中的什么地方。