It took me quite some time to figure out how to change the Subsites and Pages settings by code. I finally manged to change them. The setting “Show subsites” can be altered in 2 ways. I was only able to change the “Show pages” on a publishing site.
Method 1 (“Show subsites” only)
With this code you will access the AllProperties setting of the Sharepoint Site and change the __IncludeSubSitesInNavigation value. Somehow there is no such property for the “Show pages”.
web.AllProperties[“__IncludeSubSitesInNavigation”] = “False”;
With this code the “Show pages” and “Show subsites” option are disabled. To access these properties your site must be a publishing site.
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
publishingWeb.IncludePagesInNavigation = false;
publishingWeb.IncludeSubSitesInNavigation = false;