Export SharePoint Server Report

To export a SharePoint server report with the Bold Reports® ASP.NET MVC Report Writer, set the processing mode to remote and set the report server URL and report path in the Web API. The Report Writer exports these RDL reports to popular file formats like PDF, Microsoft Word, Microsoft Excel, and CSV.

You need an ASP.NET MVC Report Writer application. If you do not have one, create it by following the ASP.NET MVC Report Writer getting started guide.

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

[HttpPost]
public ActionResult 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 Bold Reports® Report Server URL with the file extension.

How do I set forms credentials for a SharePoint server?

To set forms credentials for a SharePoint server in the Report Writer, set the ReportServerFormsCredential property with the user name and password. 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");

How do I set credentials for shared data sources?

To set credentials for shared data sources in the Report Writer, add them to the DataSourceCredentials property so that the report can connect to 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 ActionResult 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;
}