1) I created a Publishing sub-site from a Team Site
2) I De-activated the Publishing features in order to save the site
as a Template.
3) Via a VS2008 aspx page, I create the sub-site and then activate
the Publishing features for the sub-site (they are already activated
at the Site Collection level) using the following:
foreach (SPFeatureDefinition feature in
SPFarm.Local.FeatureDefinitions)
{
if (feature.DisplayName == "Publishing" || feature.DisplayName
== "PublishingWeb")
{
if (feature.Scope == SPFeatureScope.Web)
{
web.AllowUnsafeUpdates = true;
web.Features.Add(feature.Id, true);
web.Update();
}
}
}
I get no errors.
4) Yet, after running this code, I go to the Site Action and notice
that the new Publishing menu items are there - except for "Create
Pages" and also that the Navigation menu item is disabled (grayed
out).
5) I go to the Site Features and Publishing ishown as Active. Yet
when I try to deactivate it, it errors out.
If I do all of the above MANUALLY (create the site and activate the
Publishing features) then everything works fine.
Any ideas why this would not work via code?