void WebAppTreeNode_TreeNodePopulate(object sender, TreeViewCancelEventArgs e) { WebApplicationInfo webAppInfo = e.Node.Tag as WebApplicationInfo; if (webAppInfo != null) { if (webAppInfo.Application.Sites.Count >= SiteCollectionCountWarning) { string msg = String.Format(FormattedSiteCollectionCountWarningMessage, webAppInfo.Application.Sites.Count); if (MessageBox.Show(msg, "Large Number of Site Collections", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes) { e.Cancel = true; } } if (!e.Cancel) { foreach (SPSite site in webAppInfo.Application.Sites) { try { SiteCollectionInfo siteCollInfo = new SiteCollectionInfo(site, false); ExtendedTreeNode.AddNewExtendedTreeNode(e.Node.Nodes, siteCollInfo.ToString(), siteCollInfo); } finally { // guarantee SPSite is released ASAP even in face of exception site.Dispose(); } } } } }
private void PopulateTreeViewForWebApps(TreeNodeCollection treeNodes, SPWebApplicationCollection webApps) { foreach (SPWebApplication application in webApps) { WebApplicationInfo webAppInfo = new WebApplicationInfo(application, false); ExtendedTreeNode webAppTreeNode = ExtendedTreeNode.AddNewExtendedTreeNode(treeNodes, webAppInfo.ToString(), true, webAppInfo); webAppTreeNode.TreeNodePopulate += new ExtendedTreeNode.TreeNodeEventHandler(WebAppTreeNode_TreeNodePopulate); } }