显示嵌入在DLL文件中的.RDLC报告
问题描述:
我有一个Windows服务和表单应用程序使用的报告。因此,我想将报表嵌入一个可以供双方使用的DLL文件中。
I have a report that is used by a windows service and a form application. So, I want to put embed the report in a DLL file that can be used by both.
问题是,如果我尝试设置ReportViewer的ReportEmbeddedResource属性,控制在我的Windows窗体应用程序中,它将在Windows窗体应用程序中搜索资源,而不是dll文件。
The problem is that if I try to set the ReportEmbeddedResource property of a ReportViewer control in my windows form app, it will search the windows form app for the resource, not the dll file.
例如:Windows窗体应用程序中的代码:
e.g.: Code from the windows form app:
rv.LocalReport.ReportEmbeddedResource = "MyReportInMyDLLFile.rdlc"
如何使上述命令在DLL文件中查找嵌入式资源?
How can I make the above command look for the embedded resource in my DLL file?
答
应该执行以下操作:
Assembly assembly = Assembly.LoadFrom("Reports.dll");
Stream stream = assembly.GetManifestResourceStream("Reports.MyReport.rdlc");
reportViewer.LocalReport.LoadReportDefinition(stream);