Condividi tramite


Uso dell'accesso con URL in un'applicazione Windows

Sebbene l'accesso tramite URL a un server di report sia ottimizzato per un ambiente Web, è anche possibile usare l'accesso tramite URL per incorporare report di Reporting Services in un'applicazione Microsoft Windows. Tuttavia, l'accesso con URL che coinvolge Windows Form richiede comunque l'uso della tecnologia Web browser. È possibile usare gli scenari di integrazione seguenti con l'accesso con URL e Windows Form:

  • Visualizzare un report da un'applicazione Windows Form avviando un Web browser a livello di codice.

  • Utilizzare il WebBrowser controllo in un Windows Form per visualizzare un report.

Avvio di Internet Explorer da un Windows Form

È possibile usare la Process classe per accedere a un processo in esecuzione in un computer. La Process classe è un utile costrutto di Microsoft .NET Framework per l'avvio, l'arresto, il controllo e il monitoraggio delle applicazioni. Per visualizzare un report specifico nel database del server di report, è possibile avviare il processo IExplore passando l'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 fa clic su 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);  
   }  
}  

Incorporamento di un controllo browser in un Windows Form

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

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

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

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

  3. Trascinare il WebBrowsercontrollo nell'area di progettazione di Windows Form.

    Il WebBrowsercontrollo denominato webBrowser1 viene aggiunto al modulo

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

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

Vedere anche

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