次の方法で共有


URL アクセスを使用して Reporting Services を統合する - Windows アプリケーション

レポート サーバーへの URL アクセスは Web 環境用に最適化されていますが、URL アクセスを使用して Reporting Services レポートを Microsoft Windows アプリケーションに埋め込むこともできます。 ただし、Windows フォームに関連する URL アクセスでは、Web ブラウザー テクノロジを使用する必要があります。 URL アクセスと Windows フォームでは、次の統合シナリオを使用できます。

  • プログラムで Web ブラウザーを起動し、Windows フォーム アプリケーションからレポートを表示します。

  • Windows フォームで WebBrowser コントロールを使用し、レポートを表示します。

Windows フォームから Internet Explorer を起動する

Process クラスを使用して、コンピューターで実行されているプロセスにアクセスできます。 Process クラスは、アプリケーションの起動、停止、制御、および監視に役立つ Microsoft .NET Framework の構成要素です。 レポート サーバー データベースの特定のレポートを表示するには、レポートへの URL を渡して IExplore プロセスを起動できます。 次のコード例は、Microsoft Internet Explorer を起動し、ユーザーが Windows フォームのボタンを選択したときに特定のレポート 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 フォームにブラウザー コントロールを埋め込む

レポートを外部 Web ブラウザーで表示しない場合は、 WebBrowser コントロールを使用して、Windows フォームの一部として Web ブラウザーをシームレスに埋め込むことができます。

Windows フォームに WebBrowser コントロールを追加するには
  1. Microsoft C# または Microsoft Visual Basic で新しい Windows アプリケーションを作成します。

  2. [ツールボックス] ダイアログ ボックスで WebBrowser コントロールを探します。

    Toolboxが表示されない場合は、Viewメニュー項目を選択し、Toolboxを選択することでアクセスできます。

  3. WebBrowser コントロールを Windows フォームのデザイン画面にドラッグします。

    webBrowser1 という WebBrowser コントロールがフォームに追加されます。

WebBrowser コントロールを URL に指定するには、その Navigate メソッドを呼び出します。 次の例に示すように、実行時に特定の 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);