Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Activate Publishing Features via code - Create Pages not showing

  Asked By: Virginia    Date: Sep 15    Category: Sharepoint    Views: 289623

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
if (feature.DisplayName == "Publishing" || feature.DisplayName
== "PublishingWeb")
if (feature.Scope == SPFeatureScope.Web)
web.AllowUnsafeUpdates = true;
web.Features.Add(feature.Id, true);

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

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?



1 Answer Found

Answer #1    Answered By: Dante Parsons     Answered On: Sep 15

I haven't played around with the Publishing feature  this way, but I have seen in
some other features  that you will need to add a Boolean parameter for Force to
the Features.Add parameters.