Enabling the publishing features on an existing site

In addition to using the SharePoint publishing site templates, publishing capabilities may be enabled on an existing site by activating the SharePoint Server Publishing feature. In this recipe, we will activate the SharePoint Server Publishing feature on an existing site.

How to do it...

Follow these steps to enable publishing features on an existing site:

  1. Navigate to the site in your preferred web browser.
  2. Select Site settings from the Settings menu.
  3. Select Manage site features from the Site Actions section as shown in the following screenshot:
    How to do it...
  4. Activate the SharePoint Server Publishing feature.
    How to do it...

How it works...

The SharePoint Server Publishing feature creates the SharePoint libraries used for a publishing site. These include the Pages and Images libraries.

There's more...

SharePoint features may also be managed with PowerShell and code using the server-side object model. The feature identifier for the SharePoint Server Publishing Infrastructure site collection feature is f6924d36-2fa8-4f0b-b16d-06b7250180fa and the feature identifier for the SharePoint Server Publishing feature is 94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb.

Enabling the publishing features on an existing site using PowerShell

Follow these steps to enable publishing features on an existing site using PowerShell:

  1. Assign the feature identifiers to variables as follows:
    $featureSiteCollection = [GUID]"f6924d36-2fa8-4f0b-b16d-06b7250180fa"
    
    $featureSite = [GUID]"94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb"
  2. Get the site using the Get-SPWeb Cmdlet as follows:
    $web = Get-SPWeb http://sharepoint/publishing
    
  3. Ensure the site collection features collection contains the site collection feature as follows:
    if ($web.Site.Features[$featureSiteCollection] -eq $null)
    {
    $web.Site.Features.Add($featureSiteCollection)
    }
  4. Ensure the site features collection contains the site feature as follows:
    if ($web.Features[$featureSite] -eq $null)
    {
    $web.Features.Add($featureSite)
    }
  5. Use the following Dispose method to discard the SPWeb object:
    $web.Dispose()
    

Enabling the publishing features on an existing site with code using the server-side object model

Follow these steps to enable publishing features on an existing site with code using the server-side object model:

  1. Assign the feature identifiers to variables as follows:
    var FeatureSiteCollection = new Guid("f6924d36-2fa8-4f0b-b16d-06b7250180fa");
    var FeatureSite = new Guid("94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb");
  2. Open the site collection containing the site in a using statement as follows:
    using (var site = new SPSite("http://sharepoint/publishing"))
  3. Using the following code, ensure the site features' collection contains the site collection feature:
    if (site.Features[FeatureSiteCollection] == null)
    site.Features.Add(FeatureSiteCollection);
  4. Open the site in a using statement as follows:
    using (var web = site.OpenWeb())
  5. Using the following code, ensure the site features collection contains the site feature:
    if (web.Features[FeatureSite] == null)
    {
    web.Features.Add(FeatureSite);
    }

See also

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.66.185