sharepoint以编程方式获取顶部导航栏中显示的导航节点

时间:2018-02-14 12:22:11

标签: navigation sharepoint-2013 publishing

我需要在SharePoint 2013发布网站中以编程方式获取顶部导航栏中显示的导航节点 我确实搜索了它,我用代码波纹管得到它,但它给了我隐藏的项目,我想要隐藏的那些,所以如何获取项目排除隐藏的项目 (如果我在代码中使用node.IsVisible,即使项目在导航中隐藏,它也会一直给我真实的信息)

using (SPSite site = new SPSite(path))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {

                            PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);


                            SPNavigationNodeCollection navocol = publishingWeb.Navigation.GlobalNavigationNodes;

                            foreach (SPNavigationNode node in navocol)
                            {

                                    lbl.Text = lbl.Text + " + " + node.Title + "" + node.Url + "  " + node.GetType();

                            }

                            //SPNavigationNodeCollection navCol = web.Navigation.TopNavigationBar;


                            //foreach (SPNavigationNode node in navCol)
                            //{

                                //lbl.Text = lbl.Text + " + " + node.Title + "" + node.Url;

                            //}

                        });
                    }
                }

1 个答案:

答案 0 :(得分:0)

尝试使用web.AllProperties["__GlobalNavigationExcludes"],下面的代码根据我的测试工作referenced thread

string GlobalNavigationExcludes = (string)web.AllProperties["__GlobalNavigationExcludes"];
                    Hashtable ReturnExcludedUrls = new Hashtable();

                    if (!String.IsNullOrEmpty(GlobalNavigationExcludes))
                    {
                        string[] ExcludedGuids = GlobalNavigationExcludes.Split(';');

                        for (int i = 0; i < ExcludedGuids.Length - 1; i++)
                        {
                            string guid = ExcludedGuids[i];
                            Guid ExcludedGuid = new Guid(guid);

                            try
                            {
                                SPWeb SubWeb = web.Webs[ExcludedGuid];
                                ReturnExcludedUrls.Add(SubWeb.ServerRelativeUrl, "");
                            }
                            catch (Exception e1)
                            {
                                try
                                {
                                    SPListItem Page = web.Lists["Pages"].Items[ExcludedGuid];
                                    string ExcludedURL = String.Concat(web.ServerRelativeUrl, "/", Page.Url);
                                    ReturnExcludedUrls.Add(ExcludedURL, "");
                                }
                                catch (Exception e2)
                                { }
                            }
                        }
                    }