Compartir a través de


Using URL Access in a Windows Application

Actualizado: 17 de julio de 2006

Although URL access to a report server is optimized for a Web environment, you can also use URL access to embed Reporting Services reports into a Microsoft Windows application. However, URL access that involves Windows Forms still requires that you use Web browser technology. You can use the following integration scenarios with URL access and Windows Forms:

  • Display a report from a Windows Form application by starting a Web browser programmatically.
  • Use the WebBrowser control on a Windows Form to display a report.

Starting Internet Explorer from a Windows Form

You can use the Process class to access a process that is running on a computer. The Process class is a useful Microsoft .NET Framework construct for starting, stopping, controlling, and monitoring applications. To view a specific report in your report server database, you can start the IExplore process, passing in the URL to the report. The following code example can be used to start Microsoft Internet Explorer and pass a specific report URL when the user clicks a button on a Windows Form.

Private Sub viewReportButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles viewReportButton.Click
   ' Build the URL access string based on values supplied by a user
   Dim url As String = serverUrlTextBox.Text + "?" & reportPathTextBox.Text & _
   "&rs:Command=Render" & "&rs:Format=HTML4.0"

   ' If the user does not select the toolbar check box,
   ' turn the toolbar off in the HTML Viewer
   If toolbarCheckBox.Checked = False Then
      url += "&rc:Toolbar=False"
   End If
   ' load report in the Web browser
   Try
      System.Diagnostics.Process.Start("IExplore", url)
   Catch
      MessageBox.Show("The system could not start the specified report using Internet Explorer.", _
      "An error has occurred", MessageBoxButtons.OK, MessageBoxIcon.Error)
   End Try
End Sub 'viewReportButton_Click
// Sample click event for a Button control on a Windows Form
private void viewReportButton_Click(object sender, System.EventArgs e)
{
   // Build the URL access string based on values supplied by a user
   string url = serverUrlTextBox.Text + "?" + reportPathTextBox.Text +
      "&rs:Command=Render" + "&rs:Format=HTML4.0";

   // If the user does not check the toolbar check box,
   // turn the toolbar off in the HTML Viewer
   if (toolbarCheckBox.Checked == false)
      url += "&rc:Toolbar=False";

   // load report in the Web browser
   try
   {
      System.Diagnostics.Process.Start("IExplore", url);
   }

   catch (Exception)
   {
      MessageBox.Show(
         "The system could not open the specified report using Internet Explorer.", 
         "An error has occurred", MessageBoxButtons.OK, MessageBoxIcon.Error);
   }
}

For more information about the specific syntax of a report server URL access string, see URL Access Syntax.

Embedding a Browser Control on a Windows Form

If you do not want to view your report in an external Web browser, you can embed a Web browser seamlessly as part of your Windows Form using the WebBrowser control.

To add the WebBrowser control to your Windows Form
  1. Create a new Windows application in either Microsoft Visual C# or Microsoft Visual Basic.
  2. Locate the WebBrowser control in the Toolbox Dialog Box.
    If the Toolbox is not visible you can access it by clicking the View menu item and selecting Toolbox.
  3. Drag the WebBrowser control onto the design surface of your Windows Form.
    The WebBrowser control named webBrowser1 is added to the Form

You direct the WebBrowser control to a URL by calling its Navigate method. You can assign a specific URL access string to your WebBrowser control at run time as shown in the following example.

Dim url As String = "https://localhost/reportserver?/" & _
                    "AdventureWorks Sample Reports/" & _
                    "Company Sales&rs:Command=Render"
WebBrowser1.Navigate(url)
string url = "https://localhost/reportserver?/" +
             "AdventureWorks Sample Reports/" +
             "Company Sales&rs:Command=Render";
webBrowser1.Navigate(url);

Change History

Release History

17 de julio de 2006

Changed content:
  • Updated content to use the WebBrowser control.

Vea también

Conceptos

Integrating Reporting Services into Applications
Integrating Reporting Services Using the ReportViewer Controls

Otros recursos

Integrating Reporting Services Using URL Access
Integrating Reporting Services Using SOAP
URL Access

Ayuda e información

Obtener ayuda sobre SQL Server 2005