CHAPTER 8 DEPLOYING REPORTS
Note The ListChildren method returns all objects on the report server, including data sources, report parts, and
reports, not just folders. In this example, you’ll filter out everything but the folders because you’re only interested
in showing the user the folder structure. You do this by using the ItemType property of the child object and then
testing it against the string “Folder”.
Make sure the Publisher.cs form is open in the design view and double-click the Go button. This
creates an empty method to handle the button’s click event. Add the code in Listing 8-6 to the method.
Listing 8-6. Code to Populate the TreeView Control
ssrsFolders.Nodes.Clear();
rs = new ReportingService2010();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
CatalogItem[] items = null;
rs.Url = GetRSURL();
TreeNode root = new TreeNode();
root.Text = "Root";
ssrsFolders.Nodes.Add(root);
ssrsFolders.SelectedNode = ssrsFolders.TopNode;
// Retrieve a list items from the server
try
{
items = rs.ListChildren("/", true);
int j = 1;
// Iterate through the list of items and find all of the folders and display them to the user
foreach (CatalogItem ci in items)
{
if (ci.TypeName == "Folder")
{
Regex rx = new Regex("/");
int matchCnt = rx.Matches(ci.Path).Count;
if (matchCnt > j)
{
ssrsFolders.SelectedNode = ssrsFolders.SelectedNode.LastNode;
j = matchCnt;
}
else if (matchCnt < j)
{
ssrsFolders.SelectedNode =ssrsFolders.SelectedNode.Parent;
j = matchCnt;
}
AddNode(ci.Name);
}
}