//private delegate void selectDefaultNodeDelegate(); //private void selectDefaultNodeSafely() //{ // if (this.InvokeRequired) // { // this.Invoke(new selectDefaultNodeDelegate(selectDefaultNodeSafely)); // return; // } // string rememberedTargetUrl = _targetTextbox.Text.Trim().ToUpper(); // if (!Uri.IsWellFormedUriString(rememberedTargetUrl, UriKind.Absolute)) // return; // string[] urlParts = rememberedTargetUrl.Remove(0, 7).Split(new string[] { "/" }, StringSplitOptions.None); // foreach (TreeNode nodeWebApp in treeviewMain.Nodes) // foreach (TreeNode nodeSiteCol in nodeWebApp.Nodes) // { // NodeTagInfoHolder nti = (NodeTagInfoHolder)nodeSiteCol.Tag; // if (rememberedTargetUrl.StartsWith(nti.ParentSiteCol.Url.ToUpper())) // { // findChildWebNodeInSiteCollection(urlParts, 1, nodeSiteCol); // return; // } // } //} //private void findChildWebNodeInSiteCollection(string[] urlParts, int urlIndex, TreeNode subjectNode) //{ // //--loop through each of the urlParts (web url names) of the default URL until the matching treenode is found. (skip the first item which is the absolute URL) // if (subjectNode.Nodes.Count == 0) // AddChildnodes(subjectNode, false); // foreach (TreeNode nChild in subjectNode.Nodes) // { // NodeTagInfoHolder nti = (NodeTagInfoHolder)nChild.Tag; // string s = nti.SiteRelativeUrl.ToUpper().Trim(new char[] { '/' }); // if (s == urlParts[urlIndex]) // { // //-- if this is the last urlPart, then we have arrived and can select the node. // if (urlIndex == urlParts.Length - 1) // { // treeviewMain.SelectedNode = nChild; // return; // } // findChildWebNodeInSiteCollection(urlParts, urlIndex + 1, nChild); // } // } //} #endregion #region treeviewMain_AfterSelect private void treeviewMain_AfterSelect(object sender, TreeViewEventArgs e) { btnSelect.Enabled = false; lnkBrowse1.Enabled = false; SmartStepUtil.ClearRtbSafely(rtbDisplay); if (e.Node.Tag == null) { return; } SpWebInfoHolder nti = (SpWebInfoHolder)e.Node.Tag; btnSelect.Enabled = true; lnkBrowse1.Enabled = true; AddToRtbLocal(nti.AbsoluteUrl, StyleType.bodyBlueBold); AddChildNodesAsync(e.Node, true); }
public void InitTree2() { try { SPFarm farm = SPFarm.Local; foreach (SPService service in farm.Services) { if (service is SPWebService && service.Name != "WSS_Administration") { SPWebService ws = (SPWebService)service; foreach (SPWebApplication webApp in ws.WebApplications) { TreeNode nWebapp = new TreeNode(webApp.Name); nWebapp.ImageKey = "subscribe.gif"; nWebapp.SelectedImageKey = "subscribe.gif"; AddToTreeViewSafely(treeviewMain.Nodes, nWebapp, false); foreach (SPSite siteCol in webApp.Sites) { SPWeb rootWeb = siteCol.RootWeb; TreeNode nSiteCol = new TreeNode(GetTreeNodeTitle(rootWeb)); nSiteCol.ImageKey = "LINK.GIF"; nSiteCol.SelectedImageKey = "LINK.GIF"; nSiteCol.Tag = new SpWebInfoHolder(rootWeb); AddToTreeViewSafely(nWebapp.Nodes, nSiteCol, false); rootWeb.Dispose(); siteCol.Dispose(); } } break; } } doneLoadingSafely(); } catch (Exception ex) { SmartStepUtil.ClearRtbSafely(rtbDisplay); AddToRtbLocal("error: " + ex.Message, StyleType.bodyRed); SmartStepUtil.ClearPicture(imgLoading); } }