public WebSiteNodeCollection GetChildNodes(WebSiteNode node) { WebSiteNodeCollection collection = new WebSiteNodeCollection(); if (node != null) { List <WebSiteNode> Children = nodes[node].Children; foreach (WebSiteNode childNode in Children) { collection.Add(childNode); } } return(collection); }
private void InitiateProvider() { if (nodes == null) { nodes = new WebSiteNodeCollection(); } if (rootWeb != null) { string url = rootWeb.Url; } SPWeb currentWeb = SPContext.Current.Site.RootWeb; string curl = currentWeb.Url; if (rootWeb == null || rootWeb != currentWeb) { SPSite site = SPContext.Current.Site; site.CatchAccessDeniedException = false; rootWeb = site.RootWeb; rootNode = null; //if (siteMap == null) //{ siteMap = rootWeb.Lists.TryGetList("SiteMap"); if (rootNode == null && siteMap != null) { SPListItemCollection rootNodes = null; try { SPQuery query = new SPQuery(); query.Query = "<Where><Eq><FieldRef Name=\"Parent\" /><Value Type=\"Lookup\">Root</Value></Eq></Where><OrderBy><FieldRef Name=\"Position\" Ascending=\"True\" /></OrderBy>"; //query.Query = "<Where><IsNull><FieldRef Name=\"Parent\"/></IsNull></Where>"; query.ViewFields = "<FieldRef Name=\"Title\" /><FieldRef Name=\"Description\" /><FieldRef Name=\"URL\" /><FieldRef Name=\"Enabled\" /><FieldRef Name=\"Selected\" /><FieldRef Name=\"Breadcrumb\" /><FieldRef Name=\"Separator\" /><FieldRef Name=\"Icon\" /><FieldRef Name=\"LargeImage\" /><FieldRef Name=\"Parent\" /><FieldRef Name=\"Position\" /><FieldRef Name=\"ID\" />"; rootNodes = siteMap.GetItems(query); } catch (Exception ex) { ex.ToString(); } /* * try * { * string url = rootWeb.RootFolder.WelcomePage; * } * catch (Exception) * { * HttpApplication application = HttpContext.Current.ApplicationInstance; * application.Server.ClearError(); * application.Response.StatusCode = (int)HttpStatusCode.Forbidden; * throw (new HttpException((int)HttpStatusCode.Forbidden, "")); * } */ if (rootNodes != null) { rootNode = new WebSiteNode(); //nodes.Add(rootNode); try { foreach (SPListItem item in rootNodes) { string xmlData = ConvertZRowToRegularXml(item.Xml); using (System.IO.StringReader sr = new System.IO.StringReader(xmlData)) { XmlReader reader = XmlReader.Create(sr); rootNode.ReadXml(reader); } } if (rootNode.HasChildren()) { //bool isSet = false; foreach (WebSiteNode cnode in rootNode.Children) { try { nodes.Add(cnode); //int i = nodes.Add(cnode); //if (!isSet) //{ // rootNode = (WebSiteNode)nodes[i]; // isSet = true; //} FindChildNodes(cnode); } catch (Exception ex) { ex.ToString(); //throw; } } } } catch (Exception ex) { ex.ToString(); } } //} } } }