Domanda

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())
    {

    }
}
È stato utile?

Soluzione

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);
                }
       }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top