Pro SQL Server 2012 Reporting Services

(sharon) #1
CHAPTER 8  DEPLOYING REPORTS

}


catch (SoapException ex)
{
MessageBox.Show(ex.Detail.InnerXml.ToString());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}


// Make sure the user can see that the root folder is selected by default
ssrsFolders.HideSelection = false;


Right below the method for the Go button’s click event, add the following method as shown in
Listing 8-7.


Listing 8-7. AddNode Method


private void AddNode(string name) {
TreeNode newNode = new TreeNode(name);
ssrsFolders.SelectedNode.Nodes.Add(newNode);
}


You tell the ListChildren method to start at the root folder by passing in a “/” as the starting point,
and also set the recursive option to true, which causes the ListChildren method to iterate through all the
folders and subfolders on the SSRS 2008 server. You use this information to create nodes in the TreeView
control to display each folder in a hierarchy that represents the hierarchy of the folders on the server.
Use a regular expression to look for the number of “/” characters in the path of each CatalogItem to
determine how deep you are in the hierarchy (one level, two levels, and so on).


Opening the RDL File and Uploading It to the Server


Now you need to add some code to allow users to browse for the file that they want to upload. You’ll
want to limit the users to browse for files ending in “rdl” by default, because this is the native extension
for SSRS 2008 report definition files. You also want to read the selected node in the ssrsFolders TreeView
so that you know what folder users have selected to deploy the report to on the SSRS 2008 server.
Start by reading the path of the selected node from the TreeView control and turning it into a path
name you can use with SSRS 2012’s CreateCatalogItem method.
Make sure the Publisher.cs form is open in design view and double-click the Browse button. This
creates an empty method to handle the button’s click event. Add the code in Listing 8-8 to the method.


Listing 8-8. Code to Browse for an RDL File


private void browseFile_Click(object sender, EventArgs e)
{
// Get the full pathname from the treeview control
string pathName = ssrsFolders.SelectedNode.FullPath;


if (pathName == "Root")
pathName = "/";
else
Free download pdf