SP - How to get site(name/title) from navigation?
-
11-10-2020 - |
Вопрос
I want to get title/Url from of site navigation in sharepoint programmatically. how to do this ?
I have only Current.Site.Web.Url
, but not have a child to get site with index..
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
}
}
Решение
You can use the property Navigation.QuickLaunch
to get all the left navigation items
SPNavigationNodeCollection nodeCollection = oWeb.Navigation.QuickLaunch;
Then iterate through it to find Title
and Url
using (SPSite site = new SPSite("http://localhost"))
{
using (SPWeb web = site.OpenWeb("/"))
{
foreach (SPNavigationNode heading in web.Navigation.QuickLaunch)
{
Console.WriteLine("\n{0} [{1}]", heading.Title, heading.Url);
foreach (SPNavigationNode child in heading.Children)
Console.WriteLine(" {0} [{1}]", child.Title, child.Url);
}
}
}
Не связан с sharepoint.stackexchange