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.
- 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
- Create an Empty SharePoint Project
- Create a feature staplee
- Create the feature stapler
- Create FeatureAssociation.xml
- Deploy the solution
Create an Empty SharePoint Project
- Open Visual Studio 2010
- Go to the File tab, click on
"New" and then click on "Project".
- In the New Project dialog box,
expand the Visual C# node, and then select the SharePoint 2010 node.
- In the Templates pane, select
"Empty SharePoint Project".
- Enter the Name as FeatureStapling and then click "OK". Create a feature STAPLEE
Lets Create a custom List using the STAPLEE FEATURE
- In the Solution Explorer,
right-click on the Feature folder and then click on "Add Feature".
- Double-click on the feature and
enter the Title and Description for the feature.
- Select the scope as web from
the drop down list.
- Right-click on CreateListFeature and then click on the Add Event receiver
-
- 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.
In this section you will see how to create the XML file to associate the feature to the site definition.
Right-click on the solution and then click on "Deploy Solution".
Check whether the feature stapler is activated in the web application:
In this section you will see how to create a feature stapler that is used to staple the CreateListFeature to the site definition.
- In the Solution Explorer, right-click on the
Feature folder and then click on "Add Feature".
- Rename the feature to
"FeatureStapler".
- Double-click on the feature and enter the Title
and Description for the feature.
- Select the scope as WebApplication from the drop down list.
In this section you will see how to create the XML file to associate the feature to the site definition.
- In the Solution Explorer, right-click on the project, click on "Add" and then click on "New Item".
- Select the "Empty Element" template, enter the
Name and then click on "Add".
- Double-click on Elements.xml and replace with
the following:
Id - CreateListFeature feature Id.
Template Name: To which site template the feature should be associated (the format should be <site template name><configuration number>).
- 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).
Right-click on the solution and then click on "Deploy Solution".
Check whether the feature stapler is activated in the web application:
- Open Central Administration.
- Click on Manage Web Applications that is available in the Application Management section.
- Select the web application and then click on
"Manage Features" in the ribbon interface.
- Check whether the Feature Stapler feature is
activated.
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.
ReplyDeleteNế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