Search results
Suggest a FeaturePDF

Export SSRS RDL Report in Bold Reports ASP.NET Core Report Writer

The Report Writer is a class library that is used to export the RDL report with popular file formats like PDF, Microsoft Word, Microsoft CSV, and Microsoft Excel without previewing the report in the webpage. This section describes how to export the RDL report in an ASP.NET Core application using the Report Writer.

Bold Reports ASP.NET Core Report Writer works on the ASP .NET Core 2.1, ASP.NET Core 2.2, and ASP.NET Core 3.x versions.

Create an ASP.NET Core application

  1. Start Visual Studio 2019 and click Create new project.
  2. Choose ASP.NET Core Web Application, and then click Next.
  3. Change the project name, and then click Create.
  4. In the dropdown for the ASP.NET Core version, choose ASP.NET Core 2.1.
  5. Select the Web Application (Model-View-Controller) template, then click Create.

Creating a new ASP.NET Core Application Project

List of dependency libraries

  1. In the Solution Explorer tab, right-click the project or solution, and choose Manage NuGet Packages. Alternatively, select the Tools > NuGet Package Manager > Manage NuGet Packages for Solution menu command.
  2. Search for BoldReports.Net.Core package, and install them in your Core application. The following table provides details about the packages and their usage.
Package Purpose
BoldReports.Net.Core Creates Report Writer controls to export the reports.

The following table provides details about the dependency packages and its usage.

Package Purpose
Microsoft.Data.SqlClient This is an optional package. If the RDL report contains the SQL Server or SQL Azure data source, then this package should be installed.

Refer to the NuGet Packages section to learn more details about installing and configuring Report Writer NuGet packages.

The following table provides details about the dependency packages and their usage.

Package Purpose
Syncfusion.Compression.Net.Core Exports the report to a PDF, Microsoft Word, and Microsoft Excel format. It is a base library for the Syncfusion.Pdf.Net.Core, Syncfusion.DocIO.Net.Core, and Syncfusion.XlsIO.Net.Core packages.
Syncfusion.Pdf.Net.Core Exports the report to a PDF.
Syncfusion.DocIO.Net.Core Exports the report to a Word.
Syncfusion.XlsIO.Net.Core Exports the report to an Excel.
Syncfusion.OfficeChart.Net.Core It is the base library of the Syncfusion.XlsIO.Net.Core package.
Newtonsoft.Json Serializes and deserializes data for the Report Writer. It is a mandatory package for Report Writer, and the package version should be 10.0.1 or higher.

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

Server side Report Writer changes

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

  2. Create local variables inside the HomeController class.

    // 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;
    }
  3. Open the HomeController.cs file in your application and add the Export() function to load the report as a stream. Refer to the following code snippet.

    [HttpPost]
    public IActionResult Export(string writerFormat)
    {
        // Here, we have loaded the sales-order-detail sample report from application the folder wwwroot\Resources.
        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();
        ......
    }
  4. Initialize the Report Writer instance with a report stream and set the specified export format and file name for the export document.

    public IActionResult Export(string writerFormat)
    {
        ......
    
        BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
    
        string fileName = null;
        WriterFormat format;
        string type = null;
    
        fileName = "sales-order-detail.pdf";
        type = "pdf";
        format = WriterFormat.PDF;
    }
  5. You can use the Save method in the Report Writer to generate the export document along with the information of the report stream, it will return the generated file as Stream.

    writer.LoadReport(reportStream);
    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;
  6. Refer to the following complete code snippet used to get the exported file stream.

    [HttpPost]
    public IActionResult Export(string writerFormat)
    {
        // Here, we have loaded the sales-order-detail sample report from application the folder wwwroot\Resources.
        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();
    
        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);
        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;
    }

Client side changes

  1. Use the following code snippet in Index.cshtml home page to invoke the Web API from the client side.

    @{Html.BeginForm("Export", "Home", FormMethod.Post);
    {
        <div>
            <input type="submit" value="Generate" style="width: 150px;" />
        </div>
    }
        Html.EndForm();
    }
  2. You can add the export file types to the home page to choose the format you want to export in the Report Writer. Copy and paste the following code snippet in your application.

    @{Html.BeginForm("Export", "Home", FormMethod.Post);
        {
            <div class="Common">
                <div class="tablediv">
                    <div class="rowdiv">
                        <label id="design">
                            Choose the any one of the format to export the document in Report Writer.
                            <br />
                            <br />
                        </label>
                    </div>
                    <div class="rowdiv">
                        <div class="celldiv" style="padding:10px">
                            <label>
                                <strong>  Save As :</strong>
                            </label>
                            <input id="rbtnPDf" type="radio" name="writerFormat" value="PDF" checked="checked" style="margin-left: 15px" />
                            <label for="rbtnPDf" style="padding:0px 5px 0px 2px">
                                PDF
                            </label>
                            <input id="rbtnWord" type="radio" name="writerFormat" value="Word" style="margin-left: 15px" />
                            <label for="rbtnWord" style="padding:0px 5px 0px 2px">
                                Word
                            </label>
                            <input id="rbtnxls" type="radio" name="writerFormat" value="xls" style="margin-left: 15px" />
                            <label for="rbtnxls" style="padding:0px 5px 0px 2px">
                                Excel
                            </label>
                            <input id="rbtnCSV" type="radio" name="writerFormat" value="CSV" style="margin-left: 15px" />
                            <label for="rbtnCSV" style="padding:0px 25px 0px 2px ">
                                CSV
                            </label>
                            <input class="buttonStyle" type="submit" name="button" value="Generate" style="width:150px;" />
                        </div>
                    </div>
                </div>
            </div>
            Html.EndForm();
        }}
  3. Now, Run and export the report with a specified export format in your Report Writer application.

To learn more about export a report with data visualization report items, refer to the Export data visualization report items section.

  • Congratulations! You’ve completed your first ASP.NET Core Writer application! Click here to download the already created ASP.NET Core Report Writer application.

Note: You can refer to our feature tour page for the ASP.NET Core Report Writer to see its innovative features. Additionally, you can view our ASP.NET Core Report Writer examples which demonstrate the rendering of SSRS RDLC and RDL reports.