Jaa


How to hide subsite's GlobalNavigation nodes/tabs through SharePoint API?

 

When we create a site either through UI or OM, it will not come as a tab unless you check the option ‘Site Actions-->Site Setting-->Navigation-->Show subsites to true’.

On checking the option results in displaying all the subsites as ‘Tabs’. If you want to hide some of them programmatically, you need to change the ‘__GlobalNavigationExcludes’ property from the property bag of SPWeb object.

Consider I have a site with 10 subsites, I enabled the option Site Actions--> Site Settings-->Navigation--> Show subsites to 'true, I can see now 10 addtional tabs, If I say SPWeb.Navigation.GlobalNodes.Count wont return a value approx equal to 10.

 

SPSite site = new SPSite("https://nishandv3:100/Sites/DevSite/");

SPWeb web = site.OpenWeb();

string strGlobalNavigationExcludes = web.AllProperties["__GlobalNavigationExcludes"].ToString();

web.AllProperties["__GlobalNavigationExcludes"] = strGlobalNavigationExcludes + "{569F3E30-F9AF-44d5-A52C-47670FC3FEAC}";

// 569F3E30-F9AF-44d5-A52C-47670FC3FEAC" is the GUID of the web you want to hide from the navigation.

web.Update();

 

Hope this helps!

Comments