Share via


使用 URL 存取整合 Reporting Services - Windows 應用程式

雖然在網路環境中使用 URL 是存取報表伺服器的最佳方法,但您也能利用 URL 存取,將 Reporting Services 報表內嵌到 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 上內嵌瀏覽器控件

如果您不想在外部網頁瀏覽器中檢視報表,您可以使用 控件順暢地內嵌網頁瀏覽器作為 Windows Form WebBrowser 的一部分。

將 WebBrowser 控制項加入 Windows Form
  1. 在 Microsoft 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?/" & _  
                    "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);  

將 Reporting Services 整合到應用程式
使用 URL 存取整合 Reporting Services
使用 SOAP 整合 Reporting Services
使用 ReportViewer 控件整合 Reporting Services
URL 存取 (SSRS)