Export Parameter Report
To export a parameter report with the Bold Reports® ASP.NET Core Report Writer, set the report parameter default values or modify the values with the SetParameters() method of the Report Writer instance before you save the document.
You need an ASP.NET Core Report Writer application. If you do not have one, create it by following the ASP.NET Core Report Writer getting started guide.
This tutorial uses the sales-order-detail.rdl report, which you can download as the sales-order-detail.rdl sample report. You can get the reports from Bold Reports® installation location. For more information, refer to samples and demos section.
How do I set report parameters before exporting?
To set report parameters before exporting, load the report in the Report Writer, pass a list of report parameters to the SetParameters() method, and then call the Save method.
-
Create a folder
Resourcesinto thewwwrootfolder in your application. Copy and paste the sample RDL reports into theResouresfolder. -
Load the report as a stream from the application
Resourcesfolder using theFileStreamclass.public class HomeController : Controller { // IWebHostEnvironment used with sample to get the application data from wwwroot. private Microsoft.AspNetCore.Hosting.IWebHostEnvironment _hostingEnvironment; // IWebHostEnvironment initialized with controller to get the data from application data folder. public HomeController(Microsoft.AspNetCore.Hosting.IWebHostEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; } [HttpPost] public IActionResult Export(string writerFormat) { // Here, we have loaded the sample reports from application the wwwroot\Resources folder. FileStream inputStream = new FileStream(_hostingEnvironment.WebRootPath + @"\Resources\sales-order-detail.rdl", FileMode.Open, FileAccess.Read); MemoryStream reportStream = new MemoryStream(); inputStream.CopyTo(reportStream); reportStream.Position = 0; inputStream.Close(); BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter(); writer.ReportProcessingMode = ProcessingMode.Remote; ...... } } -
You can add collection of report parameters programmatically using the
ReportParameterproperty that is the list type of Report Parameter class. Refer to the following code snippet to set the report parameter name and value.List<BoldReports.Web.ReportParameter> userParameters = new List<BoldReports.Web.ReportParameter>(); userParameters.Add(new BoldReports.Web.ReportParameter() { Name = "SalesOrderNumber", Values = new List<string>() { "SO50756" } }); ........ ........ writer.SetParameters(userParameters); -
Use the
Savemethod of the Report Writer to generate the export document from the report stream. TheSavemethod returns the generated file as a stream.[HttpPost] public IActionResult Export(string writerFormat) { // Here, we have loaded the sample reports from application the wwwroot\Resources folder. FileStream reportStream = new FileStream(_hostingEnvironment.WebRootPath + @"\Resources\sales-order-detail.rdl", FileMode.Open, FileAccess.Read); BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter(); writer.ReportProcessingMode = ProcessingMode.Remote; List<BoldReports.Web.ReportParameter> userParameters = new List<BoldReports.Web.ReportParameter>(); userParameters.Add(new BoldReports.Web.ReportParameter() { Name = "SalesOrderNumber", Values = new List<string>() { "SO50756" } }); string fileName = null; WriterFormat format; string type = null; if (writerFormat == "PDF") { fileName = "sales-order-detail.pdf"; type = "pdf"; format = WriterFormat.PDF; } else if (writerFormat == "Word") { fileName = "sales-order-detail.docx"; type = "docx"; format = WriterFormat.Word; } else if (writerFormat == "CSV") { fileName = "sales-order-detail.csv"; type = "csv"; format = WriterFormat.CSV; } else { fileName = "sales-order-detail.xlsx"; type = "xlsx"; format = WriterFormat.Excel; } writer.LoadReport(reportStream); writer.SetParameters(userParameters); MemoryStream memoryStream = new MemoryStream(); writer.Save(memoryStream, format); // Download the generated export document to the client side. memoryStream.Position = 0; FileStreamResult fileStreamResult = new FileStreamResult(memoryStream, "application/" + type); fileStreamResult.FileDownloadName = fileName; return fileStreamResult; }Report parameter names are case sensitive.
-
The Report Writer now exports the parameter report in your application.