Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display .RDLC report embedded in a DLL file

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?

like image 902
Jim Avatar asked Oct 31 '08 14:10

Jim


2 Answers

Something like this should do it:

Assembly assembly = Assembly.LoadFrom("Reports.dll");
Stream stream = assembly.GetManifestResourceStream("Reports.MyReport.rdlc");
reportViewer.LocalReport.LoadReportDefinition(stream);
like image 124
gschuager Avatar answered Nov 17 '22 06:11

gschuager


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.

like image 23
Dan Higham Avatar answered Nov 17 '22 08:11

Dan Higham