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 |