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("http://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.



Hope this helps!

Comments (2)

  1. hilkean1 says:

    It is a greate Post. but with one small error. Between the old (strGlobalNavigationExcludes) and the new Guid you have to add an semikolon (;). Otherwise the complete collection crashes after an iisreset.

Skip to main content