views:

94

answers:

0

Hi, I am writing a Custom C# code that uses Reporting Services Web Service to retreive folders, and reports underneath each folder. On top of that, I want to make each of those reports linkable, so that when you click on it, the link will take you to another Web App that displays the Report. I have following Code so far, and I dun know how to get Reports added to folder. I have gotten Folders displayed so far:

private void BuildTreeView()    
{
    TreeNode RootNode = new TreeNode();

    // give root node a name
    RootNode.Text = "Report Server";
    RootNode.Expanded = true;

    // add node to treeview object
    tvCatalog.Nodes.AddAt(0, RootNode);

    // populate treeview with catalog items
    GetCatalogItems(string.Empty, RootNode);
}

/// <summary>
/// recursivly get folder items from report
/// server catalog; render to treeview control
/// </summary>
/// <param name="catalogPath"></param>
/// <param name="parentNode"></param>
private void GetCatalogItems(string catalogPath, TreeNode parentNode)
{
    CatalogItem[] items;

    try
    {
        // if catalog path is empty, use root, if not pass the folder path
        if (catalogPath.Length == 0)
        {
            items = rs.ListChildren("/", true); // no recursion (false)
        }
        else
        {
             items = rs.ListChildren(catalogPath, true); // no recursion (false)
        }

        // iterate through catalog items and populate treeview control
        foreach (CatalogItem item in items)
        {
            // if folder is hidden, skip it
            if (item.Hidden != true)
            {
                // ensure only folders are rendered
                if (item.Type.Equals(ItemTypeEnum.Folder) | item.Type == ItemTypeEnum.Report 
                    &  (item.Type != ItemTypeEnum.DataSource & item.Name != "Data Sources"))
                {          
                    TreeNode folderNode = new TreeNode(item.Name, null);
                    folderNode.ImageUrl = GetNodeImage(item.Type);
                    folderNode.Text = item.Name;
                    folderNode.Value = item.Path;
                    folderNode.ToolTip = item.Name;

                    //Add the node to the parent node collection                            

                    // recurse   
                    if (item.Type == ItemTypeEnum.Report)
                    {      
                        TreeNode reportNode = new TreeNode(item.Name, null);
                        reportNode.Text = item.Name;
                        folderNode.ChildNodes.Add(reportNode);
                        tvCatalog.Nodes.AddAt(1, reportNode);          
                    }

                    parentNode.ChildNodes.Add(folderNode);
                    GetCatalogItems(item.Path, folderNode);

                }
            }
        }
    }
    catch (Exception ex)
    {
        throw (new Exception(ex.Message));
    }
    finally
    {
        rs.Dispose();
    }
}