Activating all Publishing Feature – Programmatically & Powershell – SharePoint 2010, 2013, 2016 & Online:

Hi Everyone!!!

Today i will talk about Publishing Features!!! During this afternoon I was trying to activate Publishing Features but i wasn’t having success because Page Library not was created on activation! So there are more than two Publishing Feature that we need have in consideration, it’s not enough Activate Publishing Infrastructure Feature and Publishing Feature. If you want activate all Publishing Features you can do it pragmatically or using Powershell script:

SharePoint Server – Powershell:

 
Disable-SPFeature –identity 'publishingSite' -URL http://server/ -force
Disable-SPFeature –identity 'PublishingResources' -URL http://server/-force
Disable-SPFeature –identity 'Publishing' -URL http://server/ -force
Disable-SPFeature –identity 'PublishingLayouts' -URL http://server/ -force
Disable-SPFeature –identity 'publishingweb' -URL http://server/ -force

Enable-SPFeature –identity 'publishingSite' -URL http://server/ -force
Enable-SPFeature –identity 'PublishingResources' -URL http://server/ -force
Enable-SPFeature –identity 'Publishing' -URL http://server/ -force
Enable-SPFeature –identity 'PublishingLayouts' -URL http://server/ -force
Enable-SPFeature –identity 'publishingweb' -URL http://server/ -force

SharePoint Online – Powershell:

 
Disable-SPOFeature –Identity "F6924D36-2FA8-4f0b-B16D-06B7250180FA" -Scope Site
Disable-SPOFeature –Identity "AEBC918D-B20F-4a11-A1DB-9ED84D79C87E" -Scope Site
Disable-SPOFeature –Identity "22A9EF51-737B-4ff2-9346-694633FE4416" -Scope Web
Disable-SPOFeature –Identity "D3F51BE2-38A8-4e44-BA84-940D35BE1566" -Scope Site
Disable-SPOFeature –Identity "94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB" -Scope Web

Enable-SPOFeature –Identity "F6924D36-2FA8-4f0b-B16D-06B7250180FA" -Scope Site
Enable-SPOFeature –Identity "AEBC918D-B20F-4a11-A1DB-9ED84D79C87E" -Scope Site
Enable-SPOFeature –Identity "22A9EF51-737B-4ff2-9346-694633FE4416" -Scope Web
Enable-SPOFeature –Identity "D3F51BE2-38A8-4e44-BA84-940D35BE1566" -Scope Site
Enable-SPOFeature –Identity "94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB" -Scope Web

Also that you can activate Programmatically:

 

        private void ActivatePublishingFeatures(SPWeb web, SPSite site)
        {
            // Publishing Site
            string sharePointPublishingSite = "f6924d36-2fa8-4f0b-b16d-06b7250180fa";
            Guid sharePointPublishingSiteGuid = new Guid(sharePointPublishingSite);

            if (site.Features[sharePointPublishingSiteGuid] == null)
            {
                site.Features.Add(sharePointPublishingSiteGuid, true);
            }

            // Publishing Resources
            string sharePointPublishingResources = "aebc918d-b20f-4a11-a1db-9ed84d79c87e";
            Guid sharePointPublishingResourcesGuid = new Guid(sharePointPublishingResources);

            if (site.Features[sharePointPublishingResourcesGuid] == null)
            {
                site.Features.Add(sharePointPublishingResourcesGuid, true);
            }

            // Publishing
            string sharePointPublishing = "22a9ef51-737b-4ff2-9346-694633fe4416";
            Guid sharePointPublishingGuid = new Guid(sharePointPublishing);

            if (web.Features[sharePointPublishingGuid] == null)
            {
                web.Features.Add(sharePointPublishingGuid, true);
            }

            // Publishing Layouts
            string sharePointPublishingLayouts = "d3f51be2-38a8-4e44-ba84-940d35be1566";
            Guid sharePointPublishingLayoutsGuid = new Guid(sharePointPublishingLayouts);

            if (site.Features[sharePointPublishingLayoutsGuid] == null)
            {
                site.Features.Add(sharePointPublishingLayoutsGuid, true);
            }

            // Publishing Web
            string sharePointServerPublishingWeb = "94c94ca6-b32f-4da9-a9e3-1f3d343d7ecb";
            Guid sharePointServerPublishingWebGuid = new Guid(sharePointServerPublishingWeb);

            if (web.Features[sharePointServerPublishingWebGuid] == null)
            {
                web.Features.Add(sharePointServerPublishingWebGuid, true);
            }
        }

Thanks

Fábio Carvalho
SharePoint Consultant
|create|it|

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *