Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReportViewer: How to load report as an embeddedresource in another assembly using reflection?

I'm not really sure how to go about this. I created a generic class to open reports up for my application. The reports are contained in another DLL that is not referenced as an embedded resource though.

If I reference the DLL I can just do:
Viewer.LocalReport.ReportEmbeddedResource = "SomeLibrary.ReportName.rdlc";

However, since I'm not referencing the DLL I figure I have to get the report via reflection. This is where I'm stuck. I'm really not sure how to go about this.

like image 860
myermian Avatar asked Oct 13 '22 22:10

myermian


2 Answers

I found a way to do this by reading the RDLC and returning the Stream.

public void PrepareReport(IAppReport report)
{
   Viewer.LocalReport.LoadReportDefinition(report.GetStream());
}

With a bit of reflection I am able to pull that Stream object.

like image 162
myermian Avatar answered Nov 03 '22 20:11

myermian


System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream streamReport = assembly.GetManifestResourceStream("MyProjectOrAssemblyName.Reports.Report1.rdlc");

reportView1.ProcessingMode = ProcessingMode.Local;
reportView1.LocalReport.LoadReportDefinition(streamReport);
like image 36
Ejrr1085 Avatar answered Nov 03 '22 20:11

Ejrr1085