I’ve got a brand that I’m activating via a Feature Receiver – it’s a theme and masterpage combination, and I want it to work on Team sites too, so it does actually make sense to do it this way!
Part of the brand is that the tabs have rounded corners, and these don’t work very well with the dynamic drop down menus. You can turn this off in the master page for the site pages, but not for the applications pages. Instead, I figured I’d use a feature receiver to turn off the ‘Show Subsites’ and ‘Show Pages’ in a publishing site.
So, the code I had was this:
if (PublishingWeb.IsPublishingWeb(site))
{
PublishingWeb pwSite = PublishingWeb.GetPublishingWeb(site);
site.Properties[ORIG_PUB_SITES] = pwSite.IncludeSubSitesInNavigation.ToString();
site.Properties[ORIG_PUB_PAGES] = pwSite.IncludePagesInNavigation.ToString();
site.Properties.Update();
pwSite.IncludePagesInNavigation = false;
pwSite.IncludeSubSitesInNavigation = false;
pwSite.Update();
pwSite.Close();
}
However, this didn’t work. To describe the code, first, we check to see if the page is a PublishingWeb. If it is, I record original settings in the site properties (so I can restore them when the feature is deactivated). I turn off those navigation check boxes, update the record on the server and close the object.
After much investigation, I realised that updating the properties was invalidating the PublishingWeb object, somehow, and that my changes weren’t being recorded. In the end I had to change my code to:
if (PublishingWeb.IsPublishingWeb(site))
{
PublishingWeb pwSite = PublishingWeb.GetPublishingWeb(site);
bool showPages = pwSite.IncludePagesInNavigation;
bool showSub = pwSite.IncludeSubSitesInNavigation;
pwSite.IncludePagesInNavigation = false;
pwSite.IncludeSubSitesInNavigation = false;
pwSite.Update();
pwSite.Close();
site.Properties[ORIG_PUB_SITES] = showPages.ToString() ;
site.Properties[ORIG_PUB_PAGES] = showSub.ToString() ;
site.Properties.Update();
}
This worked nicely!
[…] mentioned before, I’ve written a brand that is a combination of Theme and Master Page, and is designed to be activated by a feature receiver. When the feature is deactivated, it should restore the previous Master Page and Theme – but it […]
[…] built a feature to active branding on a site including master page, navigation and themes, which I’ve been talking about a bit over the last few weeks. One issue, though is […]