Report Writer has support to Export RDL reports into popular file formats such as PDF, Microsoft Word, Microsoft Excel, and CSV from SSRS Report Server.
To export the SSRS Reports, set the ReportProcessingMode
, ReportServerURL
, and ReportPath
properties in Web API as shown in the following steps.
To create your first ASP.NET Core Report Writer application, refer to the Getting-started section.
Set the reportProcessignMode
API for Bold Report Writer 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;
}
Set the reportServerUrl
API on Bold Report Writer with WebServiceURL
in the WebAPI 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>/Reports_SSRS";
}
The Web Service URL should be set as
reportServerUrl
in the report writer configuration. The Web Service URL can be found from the Reporting Services Configuration manager under theWeb Service URL
section, as shown in the following image.
Set the report path for loading the reports from the SSRS Report Server. The report path should be in the format of /folder name/report name
.
[HttpPost]
public IActionResult Export(string writerFormat)
{
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
writer.ReportProcessingMode = ProcessingMode.Remote;
writer.ReportServerUrl = "http://<servername>/Reports_SSRS";
writer.ReportPath = "/SSRSSamples2/Territory Sales";
}
The report path can be found from the SSRS Report Server by navigating to the path of the report to be loaded, as shown in the following image.
The network credentials are required to load specified SSRS report from the specified SSRS Report Server using the Report Writer. Specify the ReportServerCredential
property in writer instance.
writer.ReportServerCredential = new System.Net.NetworkCredential("username", "password");
If you are facing problem to access the SSRS Report server reports, you can refer How to provide the permission for user to access the SSRS Report Server reports.
The SSRS Report Server does not provide options to get credential information of the report data source deployed on the SSRS Server. If the report has any data source that uses credentials to connect with the database, then you should specify the DataSourceCredentials
for each report data source to establish database connection.
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 the shared data sources that do not have credentials in the connection strings.
Refer to the following final code snippet example to export the SSRS report 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 = "/Report_Path";
writer.ReportServerCredential = new System.Net.NetworkCredential("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;
}