Search This Blog


Create A Simple Feature

Step 1-Create A class library project "MyFeature" in C#
Step 2-Add reference "Windows Sharepoint Services"
Step 3-Create a folder "Features" under the class library and a a folder "MyFeature" under the "Features" folder
Step 4-Add a XML file "Feature.xml" under "MyFeature" folder
Step 5-Add a schema file to your XML from the following path-
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\wss.xsd
Step 6-The content of the feature.xml will be as follows
<Feature xmlns=""
Title="My Feature"
Description="This is my first feature"
ReceiverAssembly="MyFeature, Version=, Culture=neutral, PublicKeyToken=30534ee939de1c1d"
<ElementManifests >
<ElementManifest Location="Elements.xml"/>

The Id Value must be unique and will be generated from Tools->Guid Generator".Title ,description and image will be displayed in the feature list of your web site.Scope can be Farm,WebApplication,Site,Web depending on the scenario.
ReceiverClass and ReceiverAssembly will be explain in the next section.
ElementManifests element will call another xml.

Step 6-Add "Elements.xml" under "MyFeature" folder.
The content of the Elements.xml will be as follows-
<Elements xmlns="">
<Module Name="MyModule" Path="" Url="">
<File Url="MyModule.aspx"
<CustomAction Id="SiteActionsToolbar"
Title="Go To MyModule"
<UrlAction Url="~site/MyModule.aspx"/>

CustomAction element defines where the feature will be displayed after activation.
UrlAction element defines the url of the aspx page.But to access the url we first need to define File url.

Step 7-Add a text file "MyModule.aspx" under the "MyFeature" folder.The content will be as follows
<%@ Page Language="C#" MasterPageFile="~masterurl\default.master" %>
<asp:Content ContentPlaceHolderID="PlaceHolderMain" runat="server">
<h2>Hello , This is my test page</h2>

Step 8-Add a class file under the class library

The content will be as follows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace MyFeature
public class MyFeatureReceiver:SPFeatureReceiver
public override void FeatureActivated(SPFeatureReceiverProperties properties)
SPWeb site = (SPWeb)properties.Feature.Parent;
// SPWeb site = SPContext.Current.Web;//when the scope of the feature is site
// track original site Title using SPWeb property bag
site.Properties["OriginalTitle"] = site.Title;
// update site title
site.Title = "My Feature has been activated";

public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
// reset site Title back to its original value
SPWeb site = (SPWeb)properties.Feature.Parent;
//SPWeb site = SPContext.Current.Web;//when the scope of the feature is site
site.Title = site.Properties["OriginalTitle"];


public override void FeatureInstalled(SPFeatureReceiverProperties properties)

public override void FeatureUninstalling(SPFeatureReceiverProperties properties)

Step 9-Add a strong name to your class library ,build it and copy the dll to GAC
Step 10-Open the Feature.xml and write the ReceiverClass,ReceiverAssembly according to your "MyFeatureReceiver.cs"

Your solution structure will be as follows-

Step 11-Copy your "MyFeature" folder (which is under the "Features" folder) to the following location
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES

Step 12-Install your feature by the following command in the command prompt-
stsadm -o InstallFeature -name MyFeature -force

Stsadm exe will be found in the following path
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM.EXE

Step 13-Activate your feature from the site setting->site features

Step 14-After activation , you will find the title and label under the menu

Step 15-Click on the "Go To MyModule" ,you will be navigated to your MyModule.aspx

Step 16-After deactivation of your feature ,all of these thing will be undone.

No comments: