Già in un altro post ho parlato della grande potenzialità dei web services dei Reporting Services.
In questo post vi faccio vedere come semplice recuperare folder e report creando una treeview su uno smartclient e visualizzare i report attraverso il controllo ReportView.
Come prima cosa dobbiamo referenziare un altro webservice che si chiama ReportingService2005.
try
{
//istanzio il webservices
ReportWebService.ReportingService2005 rs = ReportWebService.ReportingService2005();
//imposto le credenziali
rs.Credentials = new System.Net.NetworkCredential("user", "Password", "dominio");
//recupero solo le cartelle della root
ReportWebService.CatalogItem[] listFolder = rs.ListChildren("/", false);//Inserendo a false il secondo paramentro non viene fatta una ricerca ricorsiva
foreach (ReportWebService.CatalogItem item in listFolder)
{
//se esite la cartella data sources non l'aggiungo alla treeview
if (item.Name != "Data Sources")
{
TreeNode nodeFolder = new TreeNode(item.Name);
nodeFolder.ImageIndex = 0;
nodeFolder.SelectedImageIndex = 1;
nodeFolder.Tag = "Folder";
//recupero tutti gli item della folder
ReportWebService.CatalogItem[] listReport = rs.ListChildren(string.Concat("/", item.Name), true);
foreach (ReportWebService.CatalogItem itemReport in listReport)
{
//aggiungo solo gli item del report
if (itemReport.Type.Equals(ReportWebService.ItemTypeEnum.Report))
{
TreeNode nodeReport = new TreeNode(itemReport.Name);
nodeReport.SelectedImageIndex = 2;
nodeReport.ImageIndex = 2;
nodeReport.Tag = "Report";
nodeFolder.Nodes.Add(nodeReport);
}
}
twReports.Nodes.Add(nodeFolder);
}
}
}
catch (Exception ex)
{
//tracciare l'errore
}
E poi nell'evento after_select della treeview imposto la visualizzazione del ReportView che nel mio caso si chiama repControl
private void twReports_AfterSelect(object sender, TreeViewEventArgs e)
{
if (e.Node.Tag.Equals("Report"))
{
string urlReportServer = ReportWebService.Url;
this.repControl.ServerUrl = new Uri(urlReportServer.Substring(0,urlReportServer.LastIndexOf("/")));//localhost/ReportServer
this.repControl.ReportCredential = ReportWebService.Credentials;
this.repControl.ReportPath = string.Format("/{0}/{1}",e.Node.Parent.Text,e.Node.Text);//costruisco il path del report
this.repControl.RefreshReport();//importante richiamare questo metodo altrimenti il report non viene visualizzato
}
}