共用方式為


在 Windows 應用程式中使用 URL 存取

雖然會為 Web 環境最佳化報表伺服器的 URL 存取,不過,您也可以使用 URL 存取來將 Reporting Services 報表內嵌到 Microsoft Windows 應用程式。 不過,需要 Windows Form 的 URL 存取仍然需要您使用網頁瀏覽器技術。 您可以透過 URL 存取與 Windows Form 使用下列整合案例:

  • 透過以程式設計方式啟動網頁瀏覽器,來顯示 Windows Form 應用程式中的報表。

  • 使用 Windows Form 上的 WebBrowser 控制項顯示報表。

從 Windows Form 啟動 Internet Explorer

您可以使用 Process 類別來存取正在電腦上執行的處理序。 Process 類別是有用的 Microsoft .NET Framework 建構,可啟動、停止、控制和監視應用程式。 若要監視在報表伺服器資料庫中的特定報表,您可以啟動 IExplore 處理序,將 URL 傳遞給報表。 下列程式碼範例可用以啟動 Microsoft Internet Explorer,並在使用者按一下 Windows Form 上的按鈕時,傳遞特定的報表 URL。

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);
   }
}

在 Windows Form 上內嵌瀏覽器控制項

如果您不想在外部網頁瀏覽器中檢視報表,可以使用 WebBrowser 控制項將網頁瀏覽器緊密地內嵌成為 Windows Form 的一部分。

將 WebBrowser 控制項加入 Windows Form

  1. 使用 Microsoft Visual C# 或 Microsoft Visual Basic 建立新的 Windows 應用程式。

  2. [工具箱] 對話方塊中找出 WebBrowser 控制項。

    如果看不到 [工具箱],可以按一下 [檢視] 功能表項目,並選取 [工具箱] 來存取。

  3. WebBrowser 控制項拖曳至 Windows Form 的設計介面。

    名為 webBrowser1 的 WebBrowser 控制項會加入 Form。

您可以呼叫其 Navigate 方法,將 WebBrowser 控制項導向 URL。 您可以在執行階段將特定的 URL 存取字串指派到 WebBrowser 控制項,如下列範例所示。

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

請參閱

概念

將 Reporting Services 整合到應用程式

使用 ReportViewer 控制項整合 Reporting Services

URL 存取 (SSRS)

其他資源

使用 URL 存取整合 Reporting Services

使用 SOAP 整合 Reporting Services