Friday, June 28, 2013

STAPLING .. FEATURE STAPLING

Feature stapling is a technique that allows a feature to be stapled to a site definition by using another feature called  the "stapler" feature that defines which features are attacched to which site definition.
This allows for a feature to be automatically activated on a site created from a site definition without the need to modify the definition files (onet.xml). 

Causes the attachment of a Feature to all new instances of sites that use a given site definition, without modifying the site definition or creating code routines to activate the Feature on each site. Also known as a feature site template association,
Feature Stapling can be created for the site definition that is already in use. Feature Stapling has two features.
  1. A Stapler feature: that staples another feature to the site definition
2        2 .    A Staplee feature: that which will be stapled













Scenario :
Suppose, we need to create a  custom list by default whenever a  new site is created using the Team Site template.
What Shall we do ?

GO FOR FEATURE STAPLING



Steps involved


  1. Create an  Empty SharePoint Project
  2. Create a feature staplee
  3. Create the feature stapler
  4. Create FeatureAssociation.xml
  5. Deploy the solution
Create an Empty SharePoint Project
  1. Open Visual Studio 2010
  2. Go to the File tab, click on "New" and then click on "Project".
  3. In the New Project dialog box, expand the Visual C# node, and then select the SharePoint 2010 node.
  4. In the Templates pane, select "Empty SharePoint Project".

  5. Share1.jpg
  6. Enter the Name as FeatureStapling and then click "OK".                                                                                  Create a feature STAPLEE

Lets Create a custom List using the STAPLEE FEATURE
  1. Share3.jpg
  2. In the Solution Explorer, right-click on the Feature folder and then click on "Add Feature". 
  3. Double-click on the feature and enter the Title and Description for the feature. 
  4. Select the scope as web from the drop down list.
  5. Right-click on CreateListFeature and then click on the Add Event receiver
  6. Share5.jpg


  7.  
  8. Double-click on CreateListFeature.EventReceiver.cs and write code to create a custom list in the activated event  

Create feature stapler
In this section you will see how to create a feature stapler that is used to staple the CreateListFeature to the site definition.

  1. In the Solution Explorer, right-click on the Feature folder and then click on "Add Feature".

    Share7.jpg
     
  2. Rename the feature to "FeatureStapler".

    Share8.jpg
     
  3. Double-click on the feature and enter the Title and Description for the feature.

    Share9.jpg
     
  4. Select the scope as WebApplication from the drop down list.
Create FeatureAssociation.xml
In this section you will see how to create the XML file to associate the feature to the site definition.

  1. In the Solution Explorer, right-click on the project, click on "Add" and then click on "New Item".
  2. Select the "Empty Element" template, enter the Name and then click on "Add".

    Share10.jpg
     
  3. Double-click on Elements.xml and replace with the following:

    Share11.jpg

    Id - CreateListFeature feature Id.

    Template Name: To which site template the feature should be associated (the format should be <site template name><configuration number>).
     
  4. Ensure this file is added to the FeatureStapler feature (double-click on the FeatureStapler feature and see whether in the "Items in the feature" window the Elements.xml file is available).

    Share12.jpg
Deploy the solution
Right-click on the solution and then click on "Deploy Solution".
Check whether the feature stapler is activated in the web application:

  1. Open Central Administration.
  2. Click on Manage Web Applications that is available in the Application Management section.
  3. Select the web application and then click on "Manage Features" in the ribbon interface.

    Share13.jpg
     
  4. Check whether the Feature Stapler feature is activated.


  1. Share15.jpg

1 comment:

  1. HTSolution là một công ty thiết kế web chuyên cung cấp các dịch vụ chuyên nhiệp như: Thiết kế website giá rẻ, phần mềm quản lý quán cafe, nâng cấp website….vv.
    Nếu bạn có nhu cầu sử dụng dịch vụ phần mềm quản lý hay bạn Cần làm web của công ty chúng tôi vui lòng liên hệ:
    CÔNG TY TNHH HTSOLUTION
    Địa chỉ: 78th Thăng Long - P.4 - Q.Tân Bình - TP.HCM
    Điện thoại: (08) 6267 3377 (Anh Hoàng) or 0985327297 (Anh Trường)
    Email:Info@htsolution.vn

    ReplyDelete

Rename a Web Application in Sharepoint : A solution using powershell

Here is a small script that will enable you all to change a SharePoint Web Application name . We can use the following SharePoint Pow...