Coach


In pieno rock ".net" roll
Anno 2011

Anno 2010

Anno 2009

Anno 2008

Anno 2007

Anno 2006

Anno 2005

Reporting Services 2005: creare una treeview dinamica con gli elementi del server

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

}

}

 

 

Categoria: SQL Server e BI
lunedì, 30 apr 2007 Ore. 13.39
  • Views Home Page: 295.294
  • Views Posts: 810.569
  • Views Gallerie: 347.831
  • n° Posts: 484
  • n° Commenti: 275












Copyright © 2002-2007 - Blogs 2.0
dotNetHell.it | Home Page Blogs
ASP.NET 2.0 Windows 2003