maandag 1 november 2010

Overview of SharePoint features

Features in SharePoint are one of the most import aspects and is surely something you really need to master. You can see features as the building blocks of SharePoint and your custom solutions. Most of the times your solution will be deployed as a (combination of) feature adding extra functionality to the platform.

- Features are the building blocks of your solution
- Features can contain elements like extra menu items, custom list templates, content types, site columns, …
- Features can contain event handlers: in SharePoint you can react on certain events and then do your own stuff. Some of the events you can use: item created, item updated, site created, … . There is a dedicated post for this.
- Features can depend on other features: this means that you can make one big main feature, make your ‘sub features’ hidden and activate them all at once by activating that main feature.
- Features can be stapled: this means that you can link features to certain site templates. If a site based on such a template is created, the features will be activated as well. This technique is mainly used to customize the ‘my site’.

Features are located in the FEATURES folder (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES) on the hard disk of each farm server to which they are deployed. It’s always a good idea to take a peak there and see how the out of the box features are built.

How to create a feature

A feature almost always exists of a feature.xml file which tells something about the feature and a second (collection of) xml file referred to in the feature.xml file which tells what the feature should do exactly. The most important attributes are:

- Title and description
- Scope: your feature can be available on farm, web application, site collection or web level
- Hidden
- ImageUrl: provides a custom icon image in the list of features in SharePoint
- Version

In SharePoint 2007 / Visual Studio 2008 you had to manually create these XML files. With Visual Studio 2010 this has all changed as the development support for building SharePoint solutions has become much better.

To create a new feature in Visual Studio 2010:

- I started from an empty SharePoint project:
Untitled

- Right click on ‘Features’ –> ‘Add feature’
Untitled

- Name the feature and select your scope. The scope depends on which level of the farm the feature needs to be active
Untitled

- Add an elements file by right clicking on your project –> Add –> New item –> in the SharePoint 2010 category –> Empty element
Untitled

The feature.xml file

Here is the feature element definition:

   1: <Feature
   2:   ActivateOnDefault = "TRUE" | "FALSE"
   3:   AlwaysForceInstall = "TRUE" | "FALSE"
   4:   AutoActivateInCentralAdmin = "TRUE" | "FALSE"
   5:   Creator = "Text" 
   6:   DefaultResourceFile =  "Text"
   7:   Description = "Text" 
   8:   Hidden = "TRUE" | "FALSE"
   9:   Id = "Text"
  10:   ImageUrl = "Text"
  11:   ImageUrlAltText = "Text"
  12:   ReceiverAssembly = "Text"
  13:   ReceiverClass = "Text"
  14:   RequireResources = "TRUE" | "FALSE"
  15:   Scope = "Text"
  16:   SolutionId = "Text"
  17:   Title = "Text"
  18:   UIVersion = "Text"
  19:   Version = "Text" >
  20: </Feature>

Please read this MSDN page to explain you what each property means.

The element.xml file

Because there is a lot you can do to extend the SharePoint platform there is not real one single element xml definition. Therefore I thought it would be better to provide you with a list of some of the things you can do with features.

- ListTemplate
- ListInstance
- Module
- ContentType
- Field
- CustomAction
- Receivers
- Control
- FeatureSiteTemplateAssociation
- Workflow
- ContentTypeBinding
- DocumentConverter

Deploying features

In Visual Studio this is all done for you behind the scenes but of course it’s also important to understand a little bit better what is going on. When you are deploying a solution with features via Visual Studio what is actually happening is that the files are copied to the correct location on all necessary servers. This is called ‘installing the feature’. The next step is to activate them and this will actually make your new functionality available.

Activation can happen in different ways:

- Via the GUI
- PowerShell or STSADM command line
- Object Model
- Site definition reference: you can build site templates in XML that reference certain features and activate them when a site based on that template is created
- Feature activation dependency
- Feature stapling

Geen opmerkingen:

Een reactie posten