Search results
Suggest a FeaturePDF

Export SharePoint Server Report

Report Writer has support to Export RDL reports into popular file formats like PDF, Microsoft Word, Microsoft Excel, and CSV from SharePoint server reports.

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

To export the SharePoint server reports, Initialize the Report Writer and set the ReportProcessingMode, ReportServerURL, and ReportPath properties in Web API as shown in the following code snippet.

[HttpPost]
public IActionResult Export(string writerFormat)
{
    BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
    writer.ReportProcessingMode = ProcessingMode.Remote;
    writer.ReportServerUrl = "http://<servername>/reportserver$instanceName";
    writer.ReportPath = "http://<servername>/reportserver$instanceName/Report_Path";
}

In SharePoint server, the ReportServerUrl will be same as your site URL. The ReportPath is relative to the Report Server URL with the file extension.

Forms credential for SharePoint Server

The forms credentials are required to load the SharePoint integrated SSRS report from the specified SharePoint integrated SSRS Report Server using the Report Viewer. Specify the ReportServerFormsCredential property to access the share point reports.

writer.ReportServerFormsCredential = new BoldReports.Web.ReportServerFormsCredential("username", "password");

Set data source credential to shared data sources

The shared data source credentials can be added to the DataSourceCredentials property to connect with the database.

List<BoldReports.Web.DataSourceCredentials> dataSourceCredentialsList = new List<BoldReports.Web.DataSourceCredentials>();
dataSourceCredentialsList.Add(new BoldReports.Web.DataSourceCredentials("datasource name", "username", "password"););
writer.SetDataSourceCredentials(dataSourceCredentialsList);

Data source credentials should be added to shared data sources that do not have credentials in the connection strings.

Refer to the following final code snippet example to export the SharePoint server reports.

[HttpPost]
public IActionResult Export(string writerFormat)
{
    BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
    writer.ReportProcessingMode = ProcessingMode.Remote;
    writer.ReportServerUrl = "http://<servername>/reportserver$instanceName";
    writer.ReportPath = "http://<servername>/reportserver$instanceName/Report_Path";
    writer.ReportServerFormsCredential = new BoldReports.Web.ReportServerFormsCredential("username", "password");
    List<BoldReports.Web.DataSourceCredentials> dataSourceCredentialsList = new List<BoldReports.Web.DataSourceCredentials>();
    dataSourceCredentialsList.Add(new BoldReports.Web.DataSourceCredentials("datasource name", "username", "password"););
    writer.SetDataSourceCredentials(dataSourceCredentialsList);

    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;
    }

    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;
}