Search results

Export Parameter Report

You can set report parameter default values or modify the values using the SetParameters() method of Report Writer instance. This section describes how to modify the exported document report parameter values.

This section requires an ASP.NET Core Report Writer application, if you don’t have, then create by referring to the Getting-Started documentation.

In this tutorial, the sales-order-detail.rdl report is used and it can be downloaded here. You can get the reports from Bold Reports installation location. For more information, refer to samples and demos section.

Set report parameters to export file

  1. Create a folder Resources into the wwwroot folder in your application. Copy and paste the sample RDL reports into the Resoures folder.

  2. To load the report as stream from the application Resources folder using the FileStream class.

    public class HomeController : Controller
    {
        // IHostingEnvironment used with sample to get the application data from wwwroot.
        private Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnvironment;
    
        // IHostingEnvironment initialized with controller to get the data from application data folder.
        public HomeController(Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment)
        {
            _hostingEnvironment = hostingEnvironment;
        }
    
        [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(reportStream);
            writer.ReportProcessingMode = ProcessingMode.Remote;
            ......
        }
    }
  3. You can add collection of report parameters programmatically using the ReportParameter property 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);
  4. You can use the Save method in Report Writer to generate the export document along with information of the report stream, it will return the generated file as 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(reportStream);
       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" }
       });
    
       writer.SetParameters(userParameters);
    
       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.doc";
           type = "doc";
           format = WriterFormat.Word;
       }
       else if (writerFormat == "CSV")
       {
           fileName = "sales-order-detail.csv";
           type = "csv";
           format = WriterFormat.CSV;
       }
       else
       {
           fileName = "sales-order-detail.xls";
           type = "xls";
           format = WriterFormat.Excel;
       }
    
       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;
    }

    The Report Parameters name should be case sensitive

  5. Now, the parameter report exported successfully in your application.