Monday, July 25, 2011

Activate Publishing Feature in SharePoint

Feature Stappling is one of the gratest feature in SharePoint. It is easiest way of attaching a feature with existing site definitions without disturbing existing template. This feature will work like plug and play concept. Therefore the features can be attached and enabled by default for any site templates. For example activate the Publishing feature when a Blank site created. This feature has two features one is “Stappler” feature which is used for attaching another feature to the site definition. The another one is “Staplee” feature which get attached with site definition. We have a simple feature stappling demo now.

Requirement: Publishing site Feature has to be enabled when a Team Site created in the Site Collection.

Solution:

1. Create a stapler feature and name it as “ActivatePublishingFeature”

2. Find the Staplee Feature GUID because the publishing feature is already deployed in the Farm. In case custom feature, need to use that Feature’s GUID

3. Install the Feature

4. Activate the feature.

Feature.xml

xml version="1.0" encoding="utf-8"?>

<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Title="ActivatePublishingFeature " Id="f7ff397a-65f1-4e82-ad7d-c75111bceef6" Scope="Farm">

<ElementManifests>

<ElementManifest Location="SitePublishingFeatureElement\Elements.xml" />

ElementManifests>

Feature>

Elements.xml

xml version="1.0" encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

<FeatureSiteTemplateAssociation Id="94C94CA6-B32F-4DA9-A9E3-1F3D343D7ECB" TemplateName="STS#0" />

Elements>

Refer this link to get the GUID of SharePoint 2010 default features.

Refer this link to get the SharePoint 2010 default web templates list


SharePoint 2010 Default web templates

SharePoint 2010 has many number of predefined site templates. A single template will be used at the time of creating a new site. New site can be created using SharePoint user interface or using Object Model (C# or VB) or PowerShell Script. The template details should be specified at the time of creating the site using Object Mode and PowerShell Script.

Predefined template IDs can be fetched using PowerShell Command " Get-SPWebTemplate"

Object model Syntax for creating new sub site

public SPWeb Add(
string strWebUrl,
string strTitle,
string strDescription,
uint nLCID,
SPWebTemplate WebTemplate,
bool useUniquePermissions,
bool bConvertIfThere
)


List of Web Templates

Template ID Template Name
GLOBAL#0 Global template
STS#0 Team Site
STS#1 Blank Site
STS#2 Document Workspace
MPS#0 Basic Meeting Workspace
MPS#1 Blank Meeting Workspace
MPS#2 Decision Meeting Workspace
MPS#3 Social Meeting Workspace
MPS#4 Multipage Meeting Workspace
CENTRALADMIN#0 Central Admin Site
WIKI#0 Wiki Site
BLOG#0 Blog
SGS#0 Group Work Site
TENANTADMIN#0 Tenant Admin Site
ACCSRV#0 Access Services Site
ACCSRV#1 Assets Web Database
ACCSRV#3 Charitable Contributions Web Database
ACCSRV#4 Contacts Web Database
ACCSRV#6 Issues Web Database
ACCSRV#5 Projects Web Database
BDR#0 Document Center
OFFILE#0 (obsolete) Records Center
OFFILE#1 Records Center
OSRV#0 Shared Services Administration Site
PPSMASite#0 PerformancePoint
BICenterSite#0 Business Intelligence Center
SPS#0 SharePoint Portal Server Site
SPSPERS#0 SharePoint Portal Server Personal Space
SPSMSITE#0 Personalization Site
SPSTOC#0 Contents area Template
SPSTOPIC#0 Topic area template
SPSNEWS#0 News Site
CMSPUBLISHING#0 Publishing Site
BLANKINTERNET#0 Publishing Site
BLANKINTERNET#1 Press Releases Site
BLANKINTERNET#2 Publishing Site with Workflow
SPSNHOME#0 News Site
SPSSITES#0 Site Directory
SPSCOMMU#0 Community area template
SPSREPORTCENTER#0 Report Center
SPSPORTAL#0 Collaboration Portal
SRCHCEN#0 Enterprise Search Center
PROFILES#0 Profiles
BLANKINTERNETCONT... Publishing Portal
SPSMSITEHOST#0 My Site Host
ENTERWIKI#0 Enterprise Wiki
SRCHCENTERLITE#0 Basic Search Center
SRCHCENTERLITE#1 Basic Search Center
SRCHCENTERFAST#0 FAST Search Center
visprus#0 Visio Process Repository