Search results
Suggest a FeaturePDF

Export RDLC Report

You can export the RDLC reports that exist on the local file system with custom business object data collection. The following steps demonstrates how to export a RDLC report using Report Writer.

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

Bind data source in Web API controller

The following steps help you to configure the Web API to render the RDLC report with business object data collection.

  1. Create a class and methods that returns business object data collection. Use the following code in your application Web API Service.

    public class ProductList
    {
        public string ProductName { get; set; }
        public string OrderId { get; set; }
        public double Price { get; set; }
        public string Category { get; set; }
        public string Ingredients { get; set; }
        public string ProductImage { get; set; }
    
        public static IList GetData()
        {
            List<ProductList> datas = new List<ProductList>();
            ProductList data = new ProductList()
            {
                ProductName = "Baked Chicken and Cheese",
                OrderId = "323B60",
                Price = 55,
                Category = "Non-Veg",
                Ingredients = "grilled chicken, corn and olives.",
                ProductImage = ""
            };
            datas.Add(data);
            data = new ProductList()
            {
                ProductName = "Chicken Delite",
                OrderId = "323B61",
                Price = 100,
                Category = "Non-Veg",
                Ingredients = "cheese, chicken chunks, onions & pineapple chunks.",
                ProductImage = ""
            };
            datas.Add(data);
            data = new ProductList()
            {
                ProductName = "Chicken Tikka",
                OrderId = "323B62",
                Price = 64,
                Category = "Non-Veg",
                Ingredients = "onions, grilled chicken, chicken salami & tomatoes.",
                ProductImage = ""
            };
            datas.Add(data);
            return datas;
        }
    }
  2. In this tutorial, the Product List.rdlc report is used, and it can be downloaded here. Copy and paste the sample RDLC reports into the Resources folder. For more information, see Samples and demos.

  3. Create a folder Resources folder in your application. Copy and paste the sample RDLC reports into the Resource folder.

  4. Open the Default.aspx.cs file in your application and add the Export()function to load the report as stream. Refer to the following code snippet.

    public partial class _Default : Page
    {
        protected void ExportButton_Click(object sender, EventArgs e)
        {
            BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
            writer.ReportPath = Server.MapPath("~/Resources/Product List.rdl");
        }
    }
  5. Initialize the Report Writer instance with created reportStream and Set the value of the ReportProcessingMode property value ProcessingMode.Local to provide the dataset collection for that RDLC report.

    BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
    writer.ReportProcessingMode = ProcessingMode.Local;
  6. Bind the business object data values collection by adding a new item to the DataSources as in the following code snippet.

    //Pass the dataset collection for report
    writer.DataSources.Clear();
    writer.DataSources.Add(new BoldReports.Web.ReportDataSource { Name = "list", Value = ProductList.GetData() });

    Data source Name is case sensitive and it should be same as in the data source name in the report definition and the Value accepts IList, DataSet, and DataTable inputs.

  7. 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.

    protected void ExportButton_Click(object sender, EventArgs e)
       {
           string fileName = null;
           WriterFormat format;
           HttpContext httpContext = System.Web.HttpContext.Current;
           BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
           writer.ReportPath = Server.MapPath("~/Resources/Product List.rdlc");
    
           if (this.ExportFormat.SelectedValue == "PDF")
           {
               fileName = "Product List.pdf";
               format = WriterFormat.PDF;
           }
           else if (this.ExportFormat.SelectedValue == "Word")
           {
               fileName = "Product List.docx";
               format = WriterFormat.Word;
           }
           else if (this.ExportFormat.SelectedValue == "Html")
           {
               fileName = "Product List.Html";
               format = WriterFormat.HTML;
           }
           else if (this.ExportFormat.SelectedValue == "PPT")
           {
               fileName = "Product List.ppt";
               format = WriterFormat.PPT;
           }
           else
           {
               fileName = "Product List.xlsx";
               format = WriterFormat.Excel;
           }
           writer.Save(fileName, format, httpContext.Response);
       }
  8. Now, the RDLC report exported successfully in your application.

Having trouble getting help?
Contact Support
Having trouble getting help?
Contact Support