CHAPTER 9 RENDERING REPORTS FROM .NET APPLICATIONS
{
try
{
rs = new SSRS_WebService.ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
SSRS_WebService.CatalogItem[] listItems = rs.ListChildren
("/Pro_SSRS/Chapter_9", false);
foreach (SSRS_WebService.CatalogItem thisItem in listItems)
{
if (thisItem.TypeName == "Report")
{
reportList.Items.Add(thisItem.Name);
}
}
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
Now that you have the form built and the drop down list populated with data from the SSRS Web
service, you can finalize the application by allowing the user to render the reports from the list. You will
now go back to the generated code for the Click event of the button you added to the Web page. In this
section, you will set the processing mode, the report server URL, and the path to the report you want to
render. Finally, the code will render the report and it will be displayed in the Report Viewer control.
Listing 9-16 shows the populated on click event in the code view of the web page.
Listing 9-16. Populating the RenderReport Button Click Method
protected void renderReport_Click(object sender, EventArgs e)
{
reportViewerWeb.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode
.Remote;
reportViewerWeb.ServerReport.ReportServerUrl = new Uri
(@"http://localhost/reportserver/");
reportViewerWeb.ServerReport.ReportPath = "/Pro_SSRS/Chapter_9/" +
reportList.SelectedItem.Value;
reportViewerWeb.ServerReport.Refresh();
}
To test the application, right click the project in the solution explorer and select Debug -> Start New
Instance. Visual Studio will start a stand-alone Web server on a random port and launch the project for
debugging. Choose the report that you put in the directory and click the Render button. If everything is
set up correctly, after you select some parameters on the report, you should get an Internet Explorer
window that resembles Figure 9-12.