Friday, December 16, 2011

Getting Started with SSRS - Show SSRS Report in ASP.NET Web Page

Reference : http://beyondrelational.com/modules/12/groups/26/tutorials/4606/getting-started-with-ssrs-part-8-show-ssrs-report-in-aspnet-web-page.aspx?utm_source=brnewsletter&utm_medium=email&utm_campaign=2011Dec
Introduction
In this article, we will cover how to use the deployed SSRS Report on to the ASP.NET Web application. In our earlier articles we have seen the steps to create and deploy the report to the Reporting Server and administer the deployed reports. In real time, we have seen requirements on accessing the reports from different clients. Let us now move ahead for the step-by-step process on accessing the SSRS report in ASP.NET web pages dynamically.
Steps
Before starting the steps to show the SSRS Report in ASP.NET Page, we should just have a look around on the previous articles to get some fair idea on how to design the report and deploy it to the Report Server.
First, open visual studio 2010 IDE and create a new ASP.NET Project as shown in the screen below. In this example we are going to use the report which we deployed in the Part 2 of this series of articles on SSRS.
Creating a new ASP.NET Web Application Project
Now in the ASPX Page, drag and drop a Scriptmanager tool, a button and a report viewer control from the toolbox as shown in the screen below.
Drag and Dropping the controls to the designer
Double click on the button. This will open a button event as shown in the screen below.
Getting the button control event
In the button click event we need to write our custom code to access the report from the SSRS Server as shown in the screen below.
Code:
1.reportViewerSam.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote;
2.reportViewerSam.ServerReport.ReportServerUrl = new Uri("http://sp2010/ReportServer");
3.reportViewerSam.ServerReport.ReportPath = "/Part2Sample/Report1";
4.reportViewerSam.ServerReport.Refresh();
Code to access the report in the SSRS Server
In the above code, we can have the Report Server URL http://sp2010/ReportServer which we need to change as per the server URL. The report path on which the report is deployed is /Part2Sample/Report1. Also, since we are accessing the server directly we need to provide the processing mode as Remote. Once we are done with the above code, execute the project by clicking the Run button or press F5 (functional key) as shown in the screen below.
Building and Executing the Project
Once the project is build successfully, we can see only the button as shown in the screen below.
Output of the executed project
Now click on Get Reports to access the report directly from the SSRS server. Clicking on Get Report will load the report and we can see the report generating as shown in the screen below.
SSRS report loading on the ASP.NET Page Output
Once the report is generated completely, we can see the report with the well formatted structure that has been deployed to the sever as shown in the screen below.

Conclusion
So, in this article we have seen how to show the deployed SSRS Report in the asp.net web application with ease without doing any formatting or any design.

No comments:

Post a Comment