SharePoint Feature allow for different types of elements to be incorporated into SharePoint site. You can define several element types: menu command, template, page instance, event handler, workflow, list definition, list instance and link command.
It is most likely that you already have features defined in your SharePoint server. In order to see what you have in it you need to navigate to the following folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES
Each feature would normally have two files associated with it: “feature.xml” and “elements.xml”. Sometimes you will also find aspx pages inside this feature folder.
In order to create feature you need to start up a new class library dll project using your Visual Studio 2005. The first step that we need to take is to re-create same folder structure as WSS 3.0 in our case we need to create TEMPLATE/FEATURES/OurFeatureName folder under the root of the project. Once we have this feature folder created, we need to create new XML file called feature.xml. Inside this file we need to define attributes of this feature. We need to make this feature hidden for instance, then we need to set attribute Hidden=”TRUE” and etc…
<Feature
Id=“can be unique id something like GUID”
Title=“My Feature“
Description=“My Feature Description.“
Scope=“Web“
Hidden=“TRUE“
ImageUrl=“menuprofile.gif“
xmlns=“http://schemas.microsoft.com/sharepoint/“>
<ElementManifests>
<ElementManifest Location=“elements.xml“ />
<ElementManifests>
</Feature>
Attributes of the feature and their meanings are summarized below:
Id: unique identifier or GUID. In order to get one you need to navigate inside your Visual Studio 2005 to menu toolbar and select Tools ? Create GUID. You will see a new window in which you need to select “4 Registry Format…” then click button called Copy and Exit. You have now new GUID that you can paste into id attribute of your feature.
- Title: Feature Title.
- Description: Feature Description.
- Scope: Scoping is important is you want to activate and deactivate feature in different SharePoint contexts (Web, WebApplication, Farm, Site).
- Hidden: It can make feature visible or invisible. It can be set via command window as well.
- ImageUrl: Sets image to be displayed along with feautre.
There are also other element that are part of the feature. Theye are ElementManifests and ElementManifest. Both are playing an important role in referencing to other XML files. Most often, there is a file called “element.xml” which defines other elements needed to the feature. Element.xml file is also created within same folder as feature.xml and has several elements in it.
<Elements xmlns=“http://schemas.microsoft.com/sharepoint/“ > <CustomAction Id=“SiteActionsToolbar“
GroupId=“SiteActions“
Location=“Microsoft.SharePoint.StandardMenu“
Sequence=“100“
Title=“Hello World“
Description=“A custom menu item added using a feature“ ImageUrl=“_layouts/images/menuprofile.gif“ >
<UrlAction Url=“http://www.google.com/>
</CustomAction>
</Elements >
Attributes are:
- Id: it has name of the menu or other page elements where we want this feature to appear.
- Title: Title of the item to be shown on the site element
- Description: Description of the feature
We also have several elements as a part of this file. UrlAction is one such element.
UrlAction: is used to redirect users if they click on the link
Once we have everything in place in terms of project files, we need to install this feature inside SharePoint Features Library. You can do it two ways, running installation process manually or creating Batch File. Batch file will look like this:
@SET DIR=”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 filesxcopy /e /y TEMPLATE\* %DIR%
Echo Installing feature%STSADM% -o InstallFeature -filename YourFeatureName\feature.xml -force
Echo Reatart IIS Worker Process
IISRESET
Make sure you restart IIS in order for this feature to be activated.
We use STSADM.EXE utility to install this feature within our SharePoint server. In case you run into problem with installing this feature you can check to see if this feature files are inside your FEATURES folder by going to “C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES” . Also, you can test your “feature.xml” and “element.xml” files for well formed XML.
SharePoint Feature