Question

I want to create site definition using VS2010, also when any site get created it should activate few feature automatically. How to use feature stapling exactly , please anyone let me know step by step I am newbie im sharepoint

Was it helpful?

Solution

Technical Details

Feature stapling is implemented through a Feature that is specifically designed to staple other Features to one or more site definitions. Feature stapling allows a Feature to be stapled to any new sites created from any site definition or from specific site definitions based on the template name identified in the appropriate WEBTEMP.xml file.

Feature Stapling has two features. A "Stapler" feature which staples another feature to the site definition and the "Staplee" feature which will be stapled. Let's take an example to understand it.

Scenario: You want to have custom list added to all of the "Team site" site definitions. This can be solved by creating a feature which will add the Custom list to the site and it can be associated with the Team site's site definition.

How to associate feature with sites / site definition?

A Feature can be associated with the sites / site definition in three different ways:

  1. You can create a site from that site definition and deploy your "custom list" feature to the site and activate it.
  2. If you already know all the required customizations before creating the site, you can include the features in the site definition (onet.xml) before you use it to create sites.

  3. If you want to automatically provision your feature when the user creates the site & you don't want to include it in the or child elements of the element that represents the site definition configuration, you can use Feature Stapling. Another reason would be when you want to do customization on out of the box site definitions, use of Feature Stapling.

This is my article which explains Feature stapling in SharePoint 2010. Please read through and this will be useful.

Customization of Site Definition & what is the best way to do that?

OTHER TIPS

Feature stappling simply means having a list of features to activate everytime a certain site definition is used (or in natural language stating "Do activate these features when any of the Site definition ID is created").

Basically there is always a Stappler (the actual feature linking one or more site definion ID with the actual features) and a Staplee (the actual feature identifier of the feature to activate).

In your case though, i'm thinking why not directly use the section dedicated to features ( - for site collection related features, and for each sub-site - including the top-level) to simply specify there? i do understand for future flexibility might be one case, but if you only plan to activate certain features only for your Site Definition, i would say - no need for Stappling (it simply hides away some of inner-workings - which in longer term might make difficult to figure out what is going on, and debugging difficult)!

You must create site definition and then add some part of text to onet.xml file look at <SiteFeatures> and <WebFeatures> part :

<?xml version="1.0" encoding="utf-8"?>
<Project Title="SiteDefinitionTitle" Revision="2" ListDir="$Resources:core,lists_Folder;" xmlns:ows="Microsoft SharePoint">
  <NavBars>
    <NavBar Name="$Resources:core,category_Top;" Separator="&amp;nbsp;&amp;nbsp;&amp;nbsp;" Body="&lt;a ID='onettopnavbar#LABEL_ID#' href='#URL#' accesskey='J'&gt;#LABEL#&lt;/a&gt;" ID="1002" />
    <NavBar Name="$Resources:core,category_Documents;" Prefix="&lt;table border='0' cellpadding='4' cellspacing='0'&gt;" Body="&lt;tr&gt;&lt;td&gt;&lt;table border='0' cellpadding='0' cellspacing='0'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='/_layouts/images/blank.gif' id='100' alt='' border='0'&gt;&amp;nbsp;&lt;/td&gt;&lt;td valign='top'&gt;&lt;a id='onetleftnavbar#LABEL_ID#' href='#URL#'&gt;#LABEL#&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;" Suffix="&lt;/table&gt;" ID="1004" />
    <NavBar Name="$Resources:core,category_Lists;" Prefix="&lt;table border='0' cellpadding='4' cellspacing='0'&gt;" Body="&lt;tr&gt;&lt;td&gt;&lt;table border='0' cellpadding='0' cellspacing='0'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='/_layouts/images/blank.gif' id='100' alt='' border='0'&gt;&amp;nbsp;&lt;/td&gt;&lt;td valign='top'&gt;&lt;a id='onetleftnavbar#LABEL_ID#' href='#URL#'&gt;#LABEL#&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;" Suffix="&lt;/table&gt;" ID="1003" />
    <NavBar Name="$Resources:core,category_Discussions;" Prefix="&lt;table border='0' cellpadding='4' cellspacing='0'&gt;" Body="&lt;tr&gt;&lt;td&gt;&lt;table border='0' cellpadding='0' cellspacing='0'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='/_layouts/images/blank.gif' id='100' alt='' border='0'&gt;&amp;nbsp;&lt;/td&gt;&lt;td valign='top'&gt;&lt;a id='onetleftnavbar#LABEL_ID#' href='#URL#'&gt;#LABEL#&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;" Suffix="&lt;/table&gt;" ID="1006" />
  </NavBars>
  <ListTemplates>
  </ListTemplates>
  <DocumentTemplates>
    <DocumentTemplate Path="STS" Name="" DisplayName="$Resources:core,doctemp_None;" Type="100" Default="FALSE" Description="$Resources:core,doctemp_None_Desc;" />
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_Word97;" Type="101" Description="$Resources:core,doctemp_Word97_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\word\wdtmpl.doc" TargetName="Forms/template.doc" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_Excel97;" Type="103" Description="$Resources:core,doctemp_Excel97_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\xl\xltmpl.xls" TargetName="Forms/template.xls" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_Powerpoint97;" Type="104" Description="$Resources:core,doctemp_Powerpoint97_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\ppt\pptmpl.pot" TargetName="Forms/template.pot" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_Word;" Type="121" Default="TRUE" Description="$Resources:core,doctemp_Word_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\word\wdtmpl.dotx" TargetName="Forms/template.dotx" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_Excel;" Type="122" Description="$Resources:core,doctemp_Excel_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\xl\xltmpl.xlsx" TargetName="Forms/template.xlsx" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_Powerpoint;" Type="123" Description="$Resources:core,doctemp_Powerpoint_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\ppt\pptmpl.pptx" TargetName="Forms/template.pptx" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_OneNote;" Type="111" Description="$Resources:core,doctemp_OneNote_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\onenote\template.onepkg" TargetName="Forms/template.onepkg" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_FP;" Type="102" Description="$Resources:core,doctemp_FP_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\fp\fptmpl.htm" TargetName="Forms/template.htm" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_BasicPage;" Type="105" Description="$Resources:core,doctemp_BasicPage_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\blankpgs\_basicpage.htm" TargetName="Forms/_basicpage.htm" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate Path="STS" DisplayName="$Resources:core,doctemp_WebPartPage;" Type="106" Description="$Resources:core,doctemp_WebPartPage_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\smartpgs\_webpartpage.htm" TargetName="Forms/_webpartpage.htm" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
    <DocumentTemplate XMLForm="TRUE" Path="STS" DisplayName="$Resources:core,doctemp_BlankForm;" Type="1000" Default="TRUE" Description="$Resources:core,doctemp_BlankForm_Desc;">
      <DocumentTemplateFiles>
        <DocumentTemplateFile Name="doctemp\xmlforms\blank\template.xml" TargetName="Forms/template.xml" Default="TRUE" />
      </DocumentTemplateFiles>
    </DocumentTemplate>
  </DocumentTemplates>
  <Configurations>
    <Configuration ID="0" Name="SiteDefinitionTemplateName">
      <Lists />
      <SiteFeatures>
        <!-- Site collection level Feature  Name-->
        <Feature ID="GUID of your feature" />
      </SiteFeatures>
      <WebFeatures>
        <!-- Web level Feature  Name-->
       <Feature ID="GUID of your feature" />
      </WebFeatures>
    </Configuration>
  </Configurations>
  <ServerEmailFooter>$Resources:ServerEmailFooter;</ServerEmailFooter>
</Project>

You shouldn't use Site definitions and use Web templates instead, because of future upgrades and the fact that MS no longer support site definitions . In case you have custom features, you could write them at proper places in the onet.xml file. Association of you custom feature to onet.xml can be done easily as you might know from site definition development. Read this MSDN manual as a jump start to the world of Web Templates.

Happy SharePointing!

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top