Integrare Reporting Services usando l'accesso con URL - Applicazione Windows

Anche se l'accesso con URL a un server di report è ottimizzato per un ambiente Web, è possibile usarlo anche per incorporare i report di Reporting Services in un'applicazione Microsoft Windows. Per l'accesso con URL che comporta l'utilizzo di Windows Form è tuttavia necessario utilizzare comunque la tecnologia del browser Web. È possibile utilizzare gli scenari di integrazione seguenti con l'accesso con URL e Windows Form:

  • Visualizzazione di un report da un'applicazione Windows Form avviando un browser a livello di programmazione.

  • Utilizzo del controllo WebBrowser in un Windows Form per visualizzare un report.

Avviare Internet Explorer da un Windows Form

È possibile utilizzare la classe Process per accedere a un processo in esecuzione in un computer. La classe Process è un costrutto Microsoft .NET Framework utile per avviare, arrestare, controllare e monitorare le applicazioni. Per visualizzare un report specifico nel database del server di report, è possibile avviare il processo IExplore, passando in URL al report. L'esempio di codice seguente può essere usato per avviare Microsoft Internet Explorer e passare un URL di report specifico quando l'utente seleziona un pulsante in un Windows Form.

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

Incorporare un controllo browser in un Windows Form

Se non si vuole visualizzare il report in un Web browser esterno, è possibile incorporare facilmente un Web browser come parte del Windows Form usando il WebBrowser controllo .

Per aggiungere il controllo WebBrowser al Windows Form
  1. Creare una nuova applicazione Windows in Microsoft C# o Microsoft Visual Basic.

  2. Individuare il controllo WebBrowser nella finestra di dialogo Casella degli strumenti.

    Se la casella degli strumenti non è visibile, è possibile accedervi selezionando la voce di menu Visualizza e selezionando Casella degli strumenti.

  3. Trascinare il controllo WebBrowser nell'area di progettazione di Windows Form.

    Il controllo WebBrowser denominato webBrowser1 verrà aggiunto al modulo

Indirizzare il controllo WebBrowser a un URL chiamando il relativo metodo Navigate. È possibile assegnare una stringa di accesso con URL specifica al controllo WebBrowser in fase di esecuzione come illustrato nell'esempio seguente.

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

Integrazione di Reporting Services nelle applicazioni
Integrazione di Reporting Services tramite l'accesso tramite URL
Integrazione di Reporting Services tramite SOAP
Integrazione di Reporting Services tramite i controlli ReportViewer
Accesso con URL (SSRS)