Publishing sites are represented in Sharepoint by PublishinWeb class which has several convenient methods and properties for working with navigation (see my previous post about basics of navigation in Sharepoint). One of them is InheritGlobalNavigation property which contains boolean value showing whether publishing site inherits navigation from parent site or it has own navigation items (corresponds to “Display the navigation items below the current site“ option from Site Settings > Navigation).
But you can determine this property also for non-publishing sites represented by regular SPWeb class. Look inside InheritGlobalNavigation property:
1: public bool InheritGlobalNavigation
2: {
3: get
4: {
5: if (this.IsRoot)
6: {
7: return false;
8: }
9: return this.Web.Navigation.UseShared;
10: }
11: set
12: {
13: if (!this.IsRoot)
14: {
15: this.Web.Navigation.UseShared = value;
16: }
17: }
18: }
Internally it reuses SPWeb.Navigation.UseShared property. So it is not necessary to obtain PublishingWeb instance if you only have SPWeb instance by extra call of PublishingWeb.GetPublishingWeb(SPWeb web) method. It is enough to have SPWeb instance and check Navigation.UseShared property.
No comments:
Post a Comment