Search This Blog


Creating Feature In Sharepoint

In this walk-through, we are going to use Microsoft Visual Studio 2005 to create a new development project for the feature. Using Visual Studio 2005 will provide color coding of XML and ASP.NET tags. Visual Studio 2005 will also provide the convenience of IntelliSense when working with the XML files required to define a feature.
Before creating the feature.xml file, consider that the files for this feature must be deployed in their own special directory inside the WSS system directory named FEATURES. The FEATURES directory is located inside another WSS system directory named TEMPLATE.
c:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
Step1.Let’s start off by creating a new Class Library DLL project named HelloWorld.
Open Visual Studio->File ->New project->Visial C#->Class Library->ManabFeature->OK

Step2.adding a folder named TEMPLATE to the root directory of the current project. Once you have created the TEMPLATE directory, create another directory inside that named FEATURES. Finally, create another directory inside the FEATURES directory using the same name as the name of the feature project. In this case the name of this directory is ManabFeature, as shown in Following Figure.

Next Create two XML File feature.xml and elements.xml under the folder ManabFeature

Step 3.Open feature.xml

Inside the TEMPLATE directory there is a directory named XML that contains several XML schemas, including one named wss.xsd.

If you associate this schema file with feature files such as feature.xml and elements.xml, Visual Studio will provide IntelliSense, which makes it much easier to author a custom feature.

So go to properties of feature.xml and then go to schemas .Then browse the following file

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML\wss.xsd

Step 4.Add the following XML to the feature.xml file to add a top-level Feature element along with attributes that define the feature itself.

<Feature Id="B1D2AF5B-DCEC-4180-9C1E-D6A091B325E6" Title="Manab Feature" Description="This is my very first custom feature" Scope="Web" Hidden="FALSE" ImageUrl="menuprofile.gif" xmlns=""
<ElementManifests> <ElementManifest Location="elements.xml" /> </ElementManifests>

You see that a feature is defined using a Feature element containing attributes such as Id, Title, Description, Version, Scope, Hidden and ImageUrl. You must create a new GUID for the Id attribute so that your feature can be uniquely identified.Go to Tools->Create GUID

You create the feature’s Title and Description attributes using user-friendly text. These attributes will be shown directly to the users on the WSS administrative pages used to activate and deactivate features.

The Scope defines the context in which the feature can be activated and deactivated. The feature we are creating has a scope equal to Web, which means it can be activated and deactivated within the context of the site. If you assign a Scope value of Site, your feature will then be activated and deactivated within the scope of a site collection. The two other possible scopes for defining a feature are WebApplication scope and Farm scope.
As you can see, the Hidden attribute has a value of FALSE. This means that, once installed within the farm, our feature can be seen by users who might want to activate it. You can also create a feature where the Hidden attribute has a value of TRUE. This has the effect of hiding the feature in the list of available features shown to users. Hidden features must be activated from the command line, through custom code, or through an activation dependency with another feature.

You will also notice that the ImageUrl attribute has a value that points to one of the graphic images that is part of the basic WSS installation. This image will be shown next to the feature in the user interface.
The last part of the feature.xml file shown previously is the ElementManifests element. This element contains inner ElementManifest elements that reference other XML files where you will define the elements that make up the feature. In our case, there is a single ElementManifest element that uses the location attribute to point to a file named element.xml.

Step 4.Now it’s time to create the element.xml file and define a single CustomAction element that will be used to add a simple menu command to the Site Actions menu. Add the following XML, which defines a CustomAction element to elements.xml.

<Elements xmlns="" <CustomAction Id="SiteActionsToolbar" GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu" Sequence="100" Title="
Manab Feature Title" Description="
This is Manab Feature" ImageUrl="_layouts/images/menuprofile.gif" > <UrlAction Url="" </CustomAction></Elements>

This CustomActions element has been designed to add a menu command to the Site Actions menu. It provides a user-friendly Title and Description as well as a URL that will be used to redirect the user when the Menu command is selected.

Step5.Now that we have created the feature.xml file and the elements.xml file to define the our feature, there are three steps involved in installing it for testing purposes. First, you must copy the ManabFeature feature directory to the WSS system FEATURES directory. Second, you must run a STSADM.EXE operation to install the feature with WSS. Finally, you must activate the feature inside the context of a WSS site. You can automate the first two steps by creating a batch file named install.bat at the root directory of the ManabFeature project and adding the following command line instructions.

REM – Remember to remove line breaks from first two lines
@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\
web server extensions\12\Template
@SET STSADM="c:\program files\common files\microsoft shared\
web server extensions\12\bin\stsadm
Echo Copying files
Echo Installing feature
%STSADM% -o InstallFeature -filename HelloWorld\feature.xml -force
Echo Restart IIS Worker Process

Actually, you can also automate the final step of activating the feature within a specific site by running the ActivateFeature operation with the STSADM utility. However, we have avoided this in our example because we want you to go through the process of explicitly activating the feature as users will do through the WSS user interface

Step6.Once the feature has been properly installed, you should be able to activate it within the context of a site. Within the top-level site of the site collection you created earlier this chapter, navigate to the Site Settings page. In the Site Administration section, click the link with the title Site Features. This should take you to a page like the one shown in figure

Step 7.You should be able to locate the ManabFeature feature on the Site Features page. You can then go through the act of clicking the button to activate the feature. Once you have done this, you should be able to drop down the Site Actions menu and see the custom menu item, as shown in Following Feagure. If you select this custom menu item, you will be redirected to the URL that was defined by the Url attribute of the UrlAction element within the elements.xml file.

After you have successfully activated the feature and tested the custom menu command, you should also experiment by returning to the Site Features page and deactivating the feature. Once you have deactivated the ManabFeature feature, you should be able to verify that the custom menu has been removed from the Site Actions menu.
You have now witnessed the fundamental principle behind features. Developers create various types of site elements that can be added or removed from a site through the process of activation and deactivation.

No comments: