Export Parameter Report

To export a parameter report with the Bold Reports® ASP.NET Web Forms 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 Web Forms Report Writer application. If you do not have one, create it by following the ASP.NET Web Forms 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.

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

  2. To load the report path on a Export() function to load the report as stream.

    public partial class _Default : Page
    {
        protected void ExportButton_Click(object sender, EventArgs e)
        {
            // Here, we have loaded the sample reports from application the Resources folder.
            BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
            writer.ReportPath = Server.MapPath("~/Resources/sales-order-detail.rdl");
            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. Use the Save method of the Report Writer to generate the export document from the report stream. The Save method returns the generated file as a stream.

    protected void ExportButton_Click(object sender, EventArgs e)
    {
       // Here, we have loaded the sample reports from application the Resources folder.
       BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
       writer.ReportPath = Server.MapPath("~/Resources/sales-order-detail.rdl");
       writer.ReportProcessingMode = ProcessingMode.Remote;
       HttpContext httpContext = System.Web.HttpContext.Current;
       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;
    
       if (this.ExportFormat.SelectedValue == "PDF")
       {
           fileName = "sales-order-detail.pdf";
           format = WriterFormat.PDF;
       }
       else if (this.ExportFormat.SelectedValue == "Word")
       {
           fileName = "sales-order-detail.docx";
           format = WriterFormat.Word;
       }
       else if (this.ExportFormat.SelectedValue == "Html")
       {
           fileName = "sales-order-detail.Html";
           format = WriterFormat.HTML;
       }
       else if (this.ExportFormat.SelectedValue == "PPT")
       {
           fileName = "sales-order-detail.ppt";
           format = WriterFormat.PPT;
       }
       else
       {
           fileName = "sales-order-detail.xlsx";
           format = WriterFormat.Excel;
       }
    
       writer.Save(fileName, format, httpContext.Response);  
    }
  5. The Report Writer now exports the parameter report in your application.