Esempio n. 1
0
        public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
        {
            //SPListItem item = siteMap.Items[new Guid(node.Key)];
            WebSiteNode websitenode = (WebSiteNode)nodes[node.Key];

            if (websitenode != null && websitenode.HasChildren())
            {
                SiteMapNodeCollection childeren = new SiteMapNodeCollection();
                foreach (WebSiteNode childNode in websitenode.Children)
                {
                    childeren.Add(new SiteMapNode(this, childNode.Key, childNode.Url, childNode.Title, childNode.Description));
                }
                return(childeren);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        private void FindChildNodes(WebSiteNode node)
        {
            InitiateProvider();

            try
            {
                SPQuery query = new SPQuery();
                query.Query      = "<Where><Eq><FieldRef Name=\"Parent\" /><Value Type=\"Lookup\">" + node.Title + "</Value></Eq></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=\"ID\" />";
                SPListItemCollection childeren = siteMap.GetItems(query);
                //DataTable childerenDT = ConvertToTable(childeren);

                if (childeren.Count >= 1)
                {
                    foreach (SPListItem item in childeren)
                    {
                        string xmlData = ConvertZRowToRegularXml(item.Xml);

                        using (System.IO.StringReader sr = new System.IO.StringReader(xmlData))
                        {
                            XmlReader reader = XmlReader.Create(sr);
                            node.ReadXml(reader);
                            //nodes[node].Children.Add(wsnode);
                        }
                    }

                    if (node.HasChildren())
                    {
                        foreach (WebSiteNode cnode in node.Children)
                        {
                            FindChildNodes(cnode);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToString();
                //throw;
            }
        }
Esempio n. 3
0
        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();
                        }
                    }
                    //}
                }
            }
        }