Partager via


Utilisation de l’accès URL dans une application Windows

Bien que l’accès URL à un serveur de rapports soit optimisé pour un environnement web, vous pouvez également utiliser l’accès URL pour incorporer des rapports Reporting Services dans une application Microsoft Windows. Toutefois, l’accès URL impliquant Windows Forms nécessite toujours l’utilisation de la technologie de navigateur web. Vous pouvez utiliser les scénarios d’intégration suivants avec l’accès URL et Windows Forms :

  • Affichez un rapport à partir d’une application Windows Form en démarrant un navigateur web par programmation.

  • Utilisez le WebBrowser contrôle sur un Windows Form pour afficher un rapport.

Démarrage d’Internet Explorer à partir d’un Windows Form

Vous pouvez utiliser la Process classe pour accéder à un processus en cours d’exécution sur un ordinateur. La Process classe est une construction Microsoft .NET Framework utile pour démarrer, arrêter, contrôler et surveiller des applications. Pour afficher un rapport spécifique dans votre base de données du serveur de rapports, vous pouvez démarrer le processus IExplore , en passant l’URL au rapport. L’exemple de code suivant peut être utilisé pour démarrer Microsoft Internet Explorer et passer une URL de rapport spécifique lorsque l’utilisateur clique sur un bouton sur un Formulaire Windows.

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

Incorporation d’un contrôle de navigateur sur un Windows Form

Si vous ne souhaitez pas afficher votre rapport dans un navigateur Web externe, vous pouvez incorporer un navigateur Web de manière transparente dans le cadre de votre Windows Form à l’aide du WebBrowser contrôle.

Pour ajouter le contrôle WebBrowser à votre Windows Form
  1. Créez une application Windows dans Microsoft Visual C# ou Microsoft Visual Basic.

  2. Recherchez le WebBrowser contrôle dans la boîte à outils, boîte de dialogue .

    Si la boîte à outils n’est pas visible, vous pouvez y accéder en cliquant sur l’élément de menu Affichage et en sélectionnant Boîte à outils.

  3. Faites glisser le WebBrowsercontrôle sur l’aire de conception de votre Windows Form.

    Le WebBrowsercontrôle nommé webBrowser1 est ajouté au formulaire

Vous dirigez le WebBrowser contrôle vers une URL en appelant sa méthode Navigate . Vous pouvez affecter une chaîne d’accès URL spécifique à votre contrôle au moment de l’exécution WebBrowser , comme illustré dans l’exemple suivant.

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

Voir aussi

Intégration de Reporting Services dans des applications
Intégration de Reporting Services via l’accès URL
Intégration de Reporting Services à l’aide de SOAP
Intégration de Reporting Services à l’aide des contrôles ReportViewer
Accès URL (SSRS)