How to launch an SSRS report in a browser window from a .NET application
By: Ray Barley | Updated: 2013-08-12 | Comments (15) | Related: > Reporting Services Development
I am working on a .NET application where we have built many reports using SQL Server Reporting Services (SSRS). A common complaint from the business users is that they don't want to open their browser and navigate to the Report Manager (or a SharePoint document library) in order to run their reports. Ideally they would like to launch a report from within the application by choosing it from a menu or clicking a button. Can you provide an example of how to do this?
There are a couple of ways that you can launch an SSRS report from a .NET application; you can:
Call the SSRS web service to render the report
Use a Report Viewer control in the application to render the report
Execute the report using URL access where the report will render in a browser window
Since the URL access method provides exactly what you need that is what I will cover in this tip. This is probably the simplest way to render a report from an application; you just need to put together a URL that represents a report request and launch the browser. When Reporting Services gets a URL request for a report, the default handling is to render the report as HTML. The report rendering is exactly the same as if you ran the report from the Report Manager web application (or a SharePoint document library).
A Simple URL Request for a Report
A URL request for a report consists of the following parts:
Web service URL of the report server
Report path (library or folder and name of report)
Parameters for the report, the HTML viewer, or report server commands. Take a look at the URL Access Parameter Reference for the complete details. It is a best practice to specify rs:Command=Render to indicate that you want to render a report.
The URL request depends on whether Reporting Services is deployed as a native instance or a SharePoint integrated instance. Check Access Report Server Items Using URL Access for the details.
If you are working with a native instance of SSRS, you can get the web service URL of the report server from the Web Service URL page in the Reporting Services Configuration Manager (the URL below is cut off; it is http://BARLEY-LAPTOP:80/ReportServer):
BARLEY-LAPTOP is the name of my laptop computer where I have a native instance of SSRS installed; 80 is the port number where the web service is running. When the web service is using port 80 you do not have to specify the port number.
Assuming I have a report named sample in the mssqltips folder, a simple URL request (without any parameters) would be:
Note that the web service URL for the report server and the report folder and name are separated by "?".
If you are working with a SharePoint Integrated instance of Reporting Services, the URL request follows the same format, but there are some slight differences:
The URL details are:
The web service URL of the report server is http://<SharePointSite>/<Sub-site>/_vti_bin/reportserver (sub-site is optional)
The SharePoint document library and report name is mssqltips/sample.rdl
Launching the Browser
Launching the browser and rendering the report is easy. We can use the Start method of the System.Diagnostics.Process class in the .NET Framework. Here is the single line of code that we need:
Reporting Services in native mode:
Reporting Services in SharePoint Integrated mode:
When this code is executed the report will be rendered in a browser window.
Adding Parameters to the URL Request
In this section I will show an example of adding parameters to the URL request. Reports typically have parameters that are used to filter the data shown on the report. In addition you can specify parameters to control the HTML output such as whether to show the parameters section, toolbar, etc.
The following screen shot shows a report that was run from the Report Manager web application used with a native instance of Reporting Services:
The following is the URL request that includes the Sales Territory Group parameter and does not show the parameter text box (must be all on one line in code):
The following screen shot shows the report rendered in the browser via the URL request (note the parameters text box isn't shown):
- Rendering an SSRS report in a browser from a .NET application can be a better approach than forcing users to run them from the Report Manager or a SharePoint document library.
- Take a look at the URL Access (SSRS) to review all of the capabilities that URL access provides.
- Download the sample code here to experiment on your own.
About the author
View all my tips
Article Last Updated: 2013-08-12