The other day I was looking for an alternative Reporting Services client, as an extra client besides the web-based Report Manager. As I couldn’t really find one I thought “how difficult could it be to write one myself?”.
And indeed, with the ReportViewer control in Visual Studio 2005 it’s really no big deal. All you need to do is drag the control onto a form, tell it that you want to load a remote report, configure the ReportServer so that it knows where to look for reports and the ReportPath so that it knows what report to load. Then call the RefreshReport() method to load the report.
When configuring the ReportPath, pay attention to the mandatory leading slash.
1: reportViewer1.ProcessingMode = Microsoft.Reporting.WinForms.ProcessingMode.Remote;
2: reportViewer1.ServerReport.ReportServerUrl = new Uri("http://localhost/reportserver");
3: reportViewer1.ServerReport.ReportPath = "/My Reports/ReportName";
4: // load report
The C# code snippet above is loading a report called ReportName, located on the local report server in a folder called My Reports.
Update: how to browse the reports on the server
Microsoft has provided an interesting sample called RSExplorer as part of the SQL Server samples, located at CodePlex. Once you’ve installed the samples you can find RSExplorer in C:\Program Files\Microsoft SQL Server\90\Samples\Reporting Services\Application Samples\RSExplorer Sample\, if you chose to install to the default folder.
The sample shows how to use the Reporting Services web service to populate a WinForms ListView with a list of folders and reports, and even how to do some basic management tasks like creating a folder or editing a report description.
When you double-click a report it will open in a popup window. What I do find funny in this sample is that the popup window, called ReportViewer, does not use the ReportViewer control. It uses a WebBrowser control instead.