Hi,
I'm making an application in C# that speaks to an report server (reporting service 2005 delivered with SQL Server 2005).
In my application I have a treeview object, in that object I want to have the structure like it is on the Report Server. So far I've managed to create some code that lists the structure but it only goes one level deep:
[CODE]
ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
// get array with children from the root folder
CatalogItem[] items = rs.ListChildren("/", false);
foreach (CatalogItem item in items)
{
// add every item in the array to my treeview
cmbRapporten.Nodes.Add(item.Name);
// get array with children from the current folder (item.Name.ToString())
CatalogItem[] childs = rs.ListChildren("/" + item.Name.ToString(), false);
foreach (CatalogItem child in childs)
{
// put every child in the correct node
cmbRapporten.Nodes[counter].Nodes.Add(child.Name);
}
counter++;
}
[CODE]
Pretty cool and almost what I wanted but what if a folder in the root has multiple subfolders that also contains reports. How would I do that. I can get the type of the item with the property item.type so I can check if it is a report or a folder.
I suppose I should write a method with passing some variables like the String with the path on the report server where it should look, and some ints because I have to know in wich node I am in...
If anyone can get me some help it would be really appreciated!
Many thanks in advance,
greetings

loading array in treeview
Larry K. Moore
I did this for RS 2000 but the code should be about the same. I also don't remember the exact function names so I'll give you the pseudo-code
void BuildTree ( string catalogPath, TreeNode parentNode )
{
//Get the catalog items (if path is empty then use root otherwise it
//is a folder path)
CatalogItem[] items = Get the catalog items (not recursive)
//Get the parent node collection (the tree's collection if parent is null
//or the parent node's Children otherwise)
For each item in items
If the user does not have permission to use the item then skip it
If the item is hidden then skip it
If the item is a folder
folderNode = Create a folder node and associate the folder path with it
Add the node to the parent node collection
BuildTree(folder path, folderNode)
If the item is a report
Create a report node and associate the report path with it
}
This works provided you want to populate the entire tree up front but can be slow if there are a lot of nodes. The alternative is to populate only the root level elements and then build the contents of a folder node when it is clicked. For Windows apps I'd go that route. For web apps I'd either build it all up front or use callbacks to avoid a postback. The only issue is determining whether to display the expand/collapse button next to the folder. You can either always display it by adding a dummy node that is removed when the real contents are brought over or actually check to see if the folder is empty. Again for Windows apps I'd probably just query for the correct value. In the web world I'd probably just always put the + there.
As another aside I would store the actual catalog item if this is a Windows app to avoid requerying the RS. For the web though just store the path because you'll have to requery the RS anyway on postback.
Hope this helps,
Michael Taylor - 5/12/06