Sharepoint 以编程方式获取出现在顶部导航栏中的导航节点
sharepoint get navigation nodes as appear in top navigation bar programmatically
我需要在 SharePoint 2013 发布网站中以编程方式获取显示在顶部导航栏中的导航节点
我确实搜索了它,我用下面的代码得到了它,但它给了我隐藏的项目,我不想得到隐藏的项目,所以如何获得项目排除隐藏项目
(如果我在代码中使用 node.IsVisible,即使该项目在导航中隐藏,它也会一直给我 true)
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;
//}
});
}
}
尝试使用 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)
{ }
}
}
}
我需要在 SharePoint 2013 发布网站中以编程方式获取显示在顶部导航栏中的导航节点 我确实搜索了它,我用下面的代码得到了它,但它给了我隐藏的项目,我不想得到隐藏的项目,所以如何获得项目排除隐藏项目 (如果我在代码中使用 node.IsVisible,即使该项目在导航中隐藏,它也会一直给我 true)
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;
//}
});
}
}
尝试使用 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)
{ }
}
}
}