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 Web Forms Report Writer application, refer to the Getting-started section.
Set the reportProcessignMode
API for Bold Report Writer as shown in the following code snippet.
protected void ExportButton_Click(object sender, EventArgs e)
{
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
writer.ReportProcessingMode = ProcessingMode.Remote;
}
Set the reportServerUrl
API for Bold Report Writer with Web Service URL
in the WebAPI as shown in the following code snippet.
protected void ExportButton_Click(object sender, EventArgs e)
{
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
when using ASP.NET Web Forms service. 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
.
protected void ExportButton_Click(object sender, EventArgs e)
{
BoldReports.Writer.ReportWriter writer = new BoldReports.Writer.ReportWriter();
writer.ReportProcessingMode = ProcessingMode.Remote;
writer.ReportServerUrl = "http://<servername>/Reports_SSRS";
writer.ReportPath= Server.MapPath("/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.
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.ReportProcessingMode = ProcessingMode.Remote;
writer.ReportServerUrl = "http://<servername>/Reports_SSRS";
writer.ReportPath= Server.MapPath("/SSRSSamples2/Territory Sales");
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);
if (this.ExportFormat.SelectedValue == "PDF")
{
fileName = "sales-order-detail.pdf";
format = WriterFormat.PDF;
}
else if (this.ExportFormat.SelectedValue == "Word")
{
fileName = "sales-order-detail.docx";
format = WriterFormat.Word;
}
else if (this.ExportFormat.SelectedValue == "Html")
{
fileName = "sales-order-detail.Html";
format = WriterFormat.HTML;
}
else if (this.ExportFormat.SelectedValue == "PPT")
{
fileName = "sales-order-detail.ppt";
format = WriterFormat.PPT;
}
else
{
fileName = "sales-order-detail.xlsx";
format = WriterFormat.Excel;
}
writer.Save(fileName, format, httpContext.Response);
}