views:

2535

answers:

4

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.

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.

e.g.: Code from the windows form app:

rv.LocalReport.ReportEmbeddedResource = "MyReportInMyDLLFile.rdlc"

How can I make the above command look for the embedded resource in my DLL file?

+2  A: 

Probably the best thing to do would be to get a stream to the RDLC resource from the other assembly, then pass that to the "LoadReportDefinition" method of the Report Viewer control.

Details of how to get a stream from an embedded resource in a different assembly can be found here : Retrieving Resources with the ResourceManager Class

Additionally, you will need to refer to the embedded resource using it's full namespace path.

E.g. if you have an application with a default namespace of TheApp, and you keep a report called "MyReport.rdlc" in a folder called "Reports", the report reference call would be:-

rv.LocalReport.ReportEmbeddedResource = "TheApp.Reports.MyReport.rdlc";
DrCamel
A: 

@Jim: Did you find out how to do this? I'm struggling with the same thing. And I'm not sure exactly how to do it. I don't understand the previous too well...

Svish
+4  A: 

Something like this should do it:

Assembly assembly = Assembly.LoadFrom("Reports.dll");
Stream stream = assembly.GetManifestResourceStream("Reports.MyReport.rdlc");
reportViewer.LocalReport.LoadReportDifinition(stream);
gschuager
A: 

Just use the full namespace of the assembly, then folder names and then the name of the file;

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

Then make sure the report file is set as an embedded resource using the properties pane.

Dan Higham