Friday, 4 April 2008

Feature in MOSS 2007

Introduction to Features

What is a feature?
Hi, I am delighted to say that. A feature in MOSS is simply a set of files, be it code, XML, web pages or CAML that will be "installed" into the SharePoint system. This being said, what you can do is actually add or "staple" this feature to a site definition so that when a new site is created, the feature will be activated as well. What you can put in a feature is really whatever you can dream up. You can add web parts, master pages, lists, fill lists with data, event receivers attached to the lists, etc. Hopefully, you are starting to understand the real scope of this here. As you can see, this is the recommended way of deploying your SharePoint Changes through the normal SDLC.

A feature can be installed on many levels or "scopes".
Farm
A farm feature is always activated and would be things like links to _layouts pages
Web Application
These would be items like Admin Links and global assemblies
Site Collection
These could be items like Web Parts, Workflows and Content Types
Site
These could be things like item receivers and list instances.

There are three types of file groups that are involved in a feature

The first and most obvious file will be the Feature.xml file. This file will be in a subdirectory (usually your feature name) under the 12 hive (\program files\common files\microsoft shared\web server extensions\12\templates\features. We are going to call our feature ItemReceivers in our example.
The second is the Element Manifest.XML file. This file is referenced by the Feature.xml file and houses pointers to all the files that will be provisioned as well as any setup for those files including CAML code.
The third are the files referenced by the Element Manifest file. These files would include aspx pages, dll's, and anything else you would likely deploy to SharePoint.

Feature
The first thing that you obviously have to do is decide on what you are going to build and add as a feature. We are going to deploy the item receiver that we built here as a feature.

Feature File
In building the feature file you will first need to generate a unique GUID for the feature itself. You can find instructions for this here. After this you will have to point to write the base XML for the feature file. It will look something like this:










Elements Manifest File

Your manifest file will act exactly as it sounds by outlining all files and placement of these files and will look something like this:








Please note that the Assembly and Class information were retrieved using the mechanism described here.

Important: Please note that there are a couple limitations to using the "Receivers" approach. You cannot associate this to a particular list instance only a type of list. You will probably want to make your own type anyway; however, this is a limitation. Also, you can only scope this at a site level. Both of these limitations can be overcome by using solution packages which will be discussed in a later post.

Manually Deploying your Feature
The first thing you will have to do is make sure that the files are copied to the correct place. You will open the command prompt and navigate to your bin folder for SharePoint.

xcopy "c:\[PathToFeatureFiles]" "c:\program files\common files\microsoft shared\web server extensions\12\templates\features" /s /y


Please GAC the assembly of your receiver by following the instructions here.

You then will need to install the feature to your SharePoint Server

stsadm -o installfeature –filename Receivers\feature.xml


Finally, you will have to activate your feature for the site

stsadm -o activatefeature -filename Receivers\feature.xml -url http://[YourSite]


--------- Have A Nice Time !!! ----------

1 comment:

Vineet said...

Nice article

1 Query how can i activate event on particular list for eg employee list instead of using Template (ListTemplateId ="101")