Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reporting services 显示嵌入在DLL文件中的.RDLC报告_Reporting Services_Rdlc_Embedded Resource - Fatal编程技术网

Reporting services 显示嵌入在DLL文件中的.RDLC报告

Reporting services 显示嵌入在DLL文件中的.RDLC报告,reporting-services,rdlc,embedded-resource,Reporting Services,Rdlc,Embedded Resource,我有一个windows服务和表单应用程序使用的报表。所以,我想把报告嵌入到一个DLL文件中,两者都可以使用 问题是,如果我尝试在windows窗体应用程序中设置ReportViewer控件的ReportEmbeddedResource属性,它将在windows窗体应用程序中搜索资源,而不是dll文件 e、 g.:来自windows窗体应用程序的代码: rv.LocalReport.ReportEmbeddedResource = "MyReportInMyDLLFile.rdlc" 如何使上述

我有一个windows服务和表单应用程序使用的报表。所以,我想把报告嵌入到一个DLL文件中,两者都可以使用

问题是,如果我尝试在windows窗体应用程序中设置ReportViewer控件的ReportEmbeddedResource属性,它将在windows窗体应用程序中搜索资源,而不是dll文件

e、 g.:来自windows窗体应用程序的代码:

rv.LocalReport.ReportEmbeddedResource = "MyReportInMyDLLFile.rdlc"

如何使上述命令在我的DLL文件中查找嵌入的资源?

最好的方法可能是从另一个程序集获取到RDLC资源的流,然后将其传递给报表查看器控件的“LoadReportDefinition”方法

有关如何从不同程序集中的嵌入式资源获取流的详细信息,请参见:

此外,您还需要使用嵌入资源的完整命名空间路径来引用它

例如,如果您有一个默认命名空间为app的应用程序,并且您在名为“Reports”的文件夹中保留了一个名为“MyReport.rdlc”的报告,那么报告引用调用将是:-

rv.LocalReport.ReportEmbeddedResource = "TheApp.Reports.MyReport.rdlc";

像这样的东西应该可以做到:

Assembly assembly = Assembly.LoadFrom("Reports.dll");
Stream stream = assembly.GetManifestResourceStream("Reports.MyReport.rdlc");
reportViewer.LocalReport.LoadReportDefinition(stream);

只需使用程序集的完整命名空间,然后是文件夹名称,然后是文件名:

rv.LocalReport.ReportEmbeddedResource = 
    "My.Assembly.Namespace.Folder1.Folder2.MyReport.rdlc";

然后确保使用属性窗格将报告文件设置为嵌入式资源。

folder1.folder2部分非常重要。谢谢我不太确定,但我想这只有在报表与代码位于同一程序集中时才有效。@GuillermoGutiérrez你是对的:报表只能在同一程序集中读取嵌入的RDLC,否则将引发异常“没有名为MyNamespace.MyReport.RDLC的定义”当我在SharePoint 2010的
应用程序页面中使用上述代码时,出现以下错误:
无法加载文件或程序集'file:///c:\windows\system32\inetsrv\Reports.dll'或其依赖项之一。系统找不到指定的文件。
,但它在WinForm应用程序中工作。这是一个古老的答案。。但它的效果和今天一样好!我遵循下面的答案。。我在两个文件夹中的另一个程序集中有一个报告,但它根本不起作用,是的,它是一个嵌入式资源。我把它复制粘贴到这个答案的第二行,它成功了!当我从签名的
.exe
而不是
dll
获取报告时,此方法是否有效?在我设置LocalReport.ReportEmbeddedResource=null后,效果非常好。与LocalReport.ReportPath相同。如果在通过流加载时未设置为null,它将尝试使用ReportEmbeddedResource或ReportPath加载资源。