kwizcom banner advertisement

How to Create a Feature in SharePoint 2010 - Step by Step

In this article, I'm demonstrating how to create a feature in SharePoint 2010 using Visual Studio 2010 in 10 easy steps:

Step 1: Create a new project in Visual Studio 2010, Choose SharePoint 2010 - Empty SharePoint Project Template, Name the project. Here I've named it as: Crescent.TitleChanger.Featurehow to create a feature in sharepoint 2010
 Step 2: Enter the existing SharePoint 2010 site's URL for debugging, Choose the solution type as "Deploy as a farm solution"
how to create a custom feature in sharepoint 2010
On clicking Finish button, Visual Studio will create a project structure as below.
how to create a new feature in sharepoint 2010
 Step 3: Right click the Features node, Choose "Add Feature"
how to create a feature receiver sharepoint 2010
Step 4: This will add a feature with name "Feature1" to the project. Rename "Feature1", it give it some meaning . I've named it as "Crescent.TitleChanger"
how to create a sharepoint feature in visual studio 2010
 Step 5: Change the Title, Descriptions of the feature accordingly. Set the Scope of the project to "Web"
how to create and deploy a feature in sharepoint 2010
Step 6: Add a Event Receiver to the project by right clicking "Crescent.TitleChanger" and choose "Add Event Receiver"
 Now, we'll get the Feature code(Crescent.EventReceiver.CS) added to our project.
how to create sharepoint feature in sharepoint 2010

Step 7: Open the Feature's event receiver code, Un-comment These two methods:
  • FeatureActivated  - We'll place the code to change the Site title to "Feature Activated" inside.
  • FeatureDeactivating  - To change the Site title to "Feature De-Activated"how to create sharepoint feature in vs 2010
 Step 8. Update the code for Feature receiver as:
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using(SPWeb web = (SPWeb)properties.Feature.Parent)
                {
                  //Change the Web's Title Property and update 
                    web.Title = "Feature Activated";
                    web.Update();
                }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            using (SPWeb web = (SPWeb)properties.Feature.Parent)
            {
                //Set the Title from Property
                web.Title = "Feature De-Activated"; 
                web.Update();
            }
        } 

Step 9: Build and deploy the Projecthow to deploy a feature in sharepoint 2010
Step 10: Activate the feature by going to Site Actions >> Site Settings >> Manage Site Features
Click on "Activate" next to our feature "Crescent - Title Changer"
how to deactivate a feature in sharepoint 2010
 See it in action! Site title has been changed to "Feature Activated"how to activate feature in sharepoint 2010 That's all! we've created a custom feature in SharePoint 2010!!
How to Create a Feature in SharePoint 2010 - Step by Step How to Create a Feature in SharePoint 2010 - Step by Step Reviewed by Salaudeen Rajack on 5:54 PM Rating: 5

3 comments:

Please Login and comment to get your questions answered!

Powered by Blogger.