CHAPTER 9 RENDERING REPORTS FROM .NET APPLICATIONS
Coding the Report Parameters Form
When you instantiate the report parameters form (GetParameters.cs), you do so by passing in the URL of
the report the user has entered in the viewer form (ViewerRVC.cs). You use this URL to determine the
report server name and the specific report the user wants to run. You need to know both of these for the
calls to the Report Server Web service. Because you’ll use this information throughout the rest of the
code, in your GetParameter class you will store them in some class-level private variables, as shown in
Listing 9-4. Add the list of private variables to your GetParameter.cs class code directly after the class
start.
Listing 9-4. Class-Level Private Variables
public partial class GetParameters : Form
{
private string url;
private string server;
private string report;
private Microsoft.Reporting.WinForms.ReportParameter[] parameters;
ReportingService2010 rs;
In the form constructor, which will take the URL string as the only parameter, we will break the
report server and report name into two separate fields. To break down the URL into the server and
report name, use the string split method and create a constructor that looks like Listing 9-5. Add this
constructor code, the code that is first run when and object of a class type is created, directly below the
private variables. You will need to add the string parameter called URL to the constructor as well.
Listing 9-5. Report Parameters Form Constructor
public GetParameters (string URL)
{
InitializeComponent();
url = URL;
string[] reportInfo = url.Split('?');
server = reportInfo[0];
report = reportInfo[1]; }
The GetParameters_Load Event
Now you get to where the real work for this dialog box takes place: the Form_Load event. To create this
method automatically, open your GetParameters form in display mode and double click your form
where there are no components, such as the top bar. This will open your form in code view and already
have the GetParameters_Load method created and link it to the form’s load event.
Next, create a ReportingService object so that you can access SSRS 2012 through the Web service that
you added as a reference earlier. Then, set your Windows credentials as the credentials to be used for
calling the Web service, like so:
rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;