A class to assist in creating Microsoft Reports.
public class MicrosoftReport
public event EventHandler<Microsoft.Reporting.WebForms.SubreportProcessingEventArgs> SubreportProcessing
public enum OutputFormats { PDF, Word, Excel, Image }
public class ReportOutput(string valueToEncrypt)
The output of the report.
The MimeType of the report.
Any returned warnings.
public ReportOutput RenderReport(string reportPath, string dataSourceName,
object dataSource, OutputFormats outputFormat = OutputFormats.PDF,
List<ReportParameter> parameters = null)
Renders a report with a single data source.
The path to the RDLC report to render.
The datasource name in the RDLC to update.
The data to put in the report.
The output format for the report.
Any parameters to be passed to the report.
public ReportOutput RenderReport(string reportPath,
List<ReportDataSource> dataSources,
OutputFormats outputFormat = OutputFormats.PDF,
List<ReportParameter> parameters = null)
Renders a report with a one or more data sources.
The path to the RDLC report to render.
A list of data sources to add to the report.
The output format for the report.
Any parameters to be passed to the report.
public static void SetSubreportDataSource(Microsoft.Reporting.WebForms.SubreportProcessingEventArgs e,
object dataSource, string name)
Set the sub report data source from within the event.
The event args passed through from the RDLC processing.
A data source to add to the sub report.
The data source name to update in the sub report.
public class MyClass : Controller{ private MicrosoftReport mr = null; public ActionResult MyReport() { var data = new DataSet(); ... // fill data mr = new MicrosoftReport(); mr.SubreportProcessing += Mr_SubreportProcessing; var pdf = mr.RenderReport(Server.MapPath("~/Rdlc/MyReport.rdlc"), "dsMyDataSet", data); ... // Email the result if needed. return File(pdf.RenderedBytes, pdf.MimeType); } private void Mr_SubreportProcessing(object sender, Microsoft.Reporting.WebForms.SubreportProcessingEventArgs e) { switch (e.ReportPath) { case "MySubReportName": var data = new DataSet(); ... // fill data MicrosoftReport.SetSubreportDataSource(e, data, "dsMySubDataSet"); } }}