雖然報表伺服器的 URL 存取已針對 Web 環境優化,但您也可以使用 URL 存取,將 Reporting Services 報表內嵌至 Microsoft Windows 應用程式。 不過,牽涉到 Windows Forms 的 URL 存取仍然需要您使用網頁瀏覽器技術。 您可以使用下列整合案例搭配 URL 存取和 Windows Forms:
以程式設計方式啟動網頁瀏覽器,以顯示來自 Windows Form 應用程式的報表。
WebBrowser使用 Windows Form 上的控件來顯示報表。
從 Windows Form 啟動 Internet Explorer
您可以使用 類別 Process 來存取電腦上執行的進程。 類別 Process 是一個實用的Microsoft .NET Framework 建構,可用於啟動、停止、控制及監視應用程式。 若要在報表伺服器資料庫中檢視特定報表,您可以啟動 IExplore 程式,並傳入報表的URL。 下列程式代碼範例可用來啟動 internet Explorer Microsoft,並在使用者按兩下 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
在 Visual C# Microsoft 或 Microsoft Visual Basic 中建立新的 Windows 應用程式。
在 [WebBrowser工具箱] 對話框中找出 控件。
如果看不到 [工具箱 ],您可以單擊 [ 檢視 ] 功能選單項並選取 [ 工具箱] 來存取它。
將 WebBrowser控件拖曳到 Windows Form 的設計介面上。
WebBrowser名為 webBrowser1 的控件會新增至 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 整合到應用程式
整合 Reporting Services 使用 URL 存取
使用 SOAP 整合 Reporting Services
使用 ReportViewer 控件整合 Reporting Services
URL 存取(SSRS)