Developing and Using Feaures in SharePoint Version 3.0

Microsoft introduced another innovation in SharePoint products and technologies 2007.  This innovation is called Features.  Using Features developer can easily add or update any events handler, chunk of code or functionality without any complexity.

Introduction

Features reduce the complexity involved in making simple site customizations, and are robust when upgrades are applied to a deployment. Features eliminate the need to copy large chunks of code to change simple functionality. Features thus reduce versioning and inconsistency issues that may arise among front-end Web servers. Features make it easier to activate or deactivate functionality in the course of a deployment, and administrators can easily transform the template or definition of a site by simply toggling a particular Feature on or off in the user interface. Features provide the following capabilities:

·         Scoping semantics for determining where custom code runs

·         Pluggable behavior for installing or uninstalling Features within a deployment

·         Pluggable behavior for activating or deactivating Features at a given scope

·         A scoped property bag for storing data required by a Feature within its scope

·         The basis of a unified framework for distributed deployment of Windows SharePoint Services solutions

Feature Components

A Feature in SharePoint 2007 is an XML file that include the description of the functionality we want to include into our site.  All the installed features resides into Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES. 

To create a new feature we need to create a new folder with the feature name and add the required XML file.  There are two XML Files which are required.

Feature.XML

This file will include Feature tags like title, Version, hidden, Description, ImageURL, RequiredResources, Scope.  Title is the name of feature that will be visible in Site Collection feature page, Hidden is property to show or hide the feature, Scope is Site or Site Collection.  Feature also have  ElementFile, ElementManifest attributes that defines it manifest or target to any other file name.

Elements.XML

Contains references to element manifests and element files that contain definitions for the Feature elements.

In this article we will create a custom menu into the site action drop down in our MOSS site collection.

Development

Ø  Start Visual Studio.NET 2005

Ø  Create a new Project and Name it XavorPortalLinkFeature

Ø  Click OK to Create the project

When Visual Studio opens the project.  The first thing we need to do is to close the Class1.cs file opened.

Creating Folders for the feature.xml

Ø  Navigate the Solution Explorer and right click on project name and Click Add -> New Folder

Ø  Name the Folder as XAVOR

Ø  Right click on Folder Created above and Click Add -> New Folder  and change its name to Xavor PortalLinkFeature

Ø  Now right click on the XavorPortalLinkFeature folder and Click Add -> New Item -> XML File.

Ø  Rename this file to Feature.xml

Ø  Remove the default line from the feature .xml

It will Look like this

Adding Feature.XML Schema File

Ø  Click inside the Feature.xml file and from Properties click on the … button on the right side the schema

Ø  Click the Add Button and browse

Adding Feature.XML Schema File

Ø  Browse to the Following Location.

Ø  Select WSS.xml if you have Beta II TR and WSS12.xml if you have Beta II only.

Ø  Click OK in Browse page

Ø  You will see WSS.xml as select schema in the list.

Ø  Click OK to Close it

Adding Elements in Feature.xml

Ø  Previous step will enable full intellisense for the development Feature.xml

Ø  The Element will be the Feature TAG.

Ø  Add ID Tag inside the feature tags and use Visual Studio.NET 2005 GUID creator to create a new GUID.

Ø  Tools – > Create GUID

Ø  Add Title inside the feature tag and give it a title.

Ø  Add Description and type some description

Ø  Add Scope and Select your scope from

o   Farm

o   Web Application

o   Site

o   Web

Ø  XML will look like this

<Feature xmlns="http://schemas.microsoft.com/sharepoint/&quot;

Id ="9ADA7D91-009E-4385-A07A-8DE5C7B754AF"

Title="XAVOR Portal Link Feature"

Description ="This Feature will add Xavor Portal Link under the Site Action dropdown"

Scope="Site"

Hidden="FALSE"

The next step is to copy this feature to the WSS Feature Directory on file system to do so

Ø  Navigate to Project Directory

Copy the STSADM.EXE to C:\STSAdmin Folder

Navigate to WSS Features (WSS stores all the isntalled features in)

C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES

 

My project feature path is

Ø  D:\Jerry’s Documents\My Documents\Visual Studio 2005\Projects\XavorPortalLinkFeature\XavorPortalLinkFeature\Xavor\

Ø  Copy XavorPortalLinkFeature folder which contains the feature.xml to the WSS Feature store.

tsadm –o installfeature –name XavorPortalLinkFeature

Ø  In Start -> Click Run and Click CMD to run Command prompt

Ø  Write CD\ and click enter

Ø  Write CD C:\STSAdmin and press enter

Ø  Run this command to register the feature.  You can also use object model to install the feature

Ø  When you see success the feature is installed.

Ø  Go to top level site and click on Site Settings

Ø  Click Modify all site settings

Ø  Click Site Collection Features under the Site Collection Administration

Ø  You will see your feature visible there you can activate and de-active the feature you want.

Ø  Test by Activating or de-activating the feature

 

We have create a basic feature.  Lets add the links to Xavor portal features

Ø  Add a new element under the feature.xml called ElementMenifest.  These tags include the core features provided by a Feature.

Ø  Add another XML file under the Feature Folder and name it as Elements.xml

Ø  Assign the same schema used in the previous file

 

<ElementManifests >

           <ElementFile Location ="Elements.xml"/>

</ElementManifests>

WSS 3.0 Schema will be available at

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

Ø  Remove the default element of the Element.xml file

Ø  Using schema intellisense this time add Element Tag

Ø  As we need to add a custom URL link to the Site Actions we need to add the following code

<Elements xmlns="http://schemas.microsoft.com/sharepoint/"&gt;

  <CustomAction

    Id="SiteActioinToolbar"

    GroupId="SiteActions"

    Location="Microsoft.SharePoint.StandardMenu"

    Sequence="1000"

    Title="Xavor Employee Portal">

    <UrlAction Url="http://portal.xavor.com"/>   

  </CustomAction>

</Elements>

Ø  Copy the feature folder again to the WSS Feature Directory

Ø  In the Run enter IISReset to restart IIS

Ø  Re-Install the feature using stsadm

stsadm -o installfeature -name XavorPortalLinkFeature – force

-force will reinstall the feature

 

Using the feature

 

Ø  Go to top level site and click on Site Settings

Ø  Click Modify all site settings

Ø  Click Site Collection Features under the Site Collection Administration

Ø  You will see your feature visible there you can activate and de-active the feature you want.

Ø  Activate the Feature

Ø  Come to the Home page

Ø  Click the Drop Down Link near the site actions.

 

Activate the Feature   

Click drop down under the site actions and see the link added to the settings.

Click on the link to verify.

 

 

A Feature could provide, for example, a "My Favorite Items" functionality that includes the following elements:

·         A custom list that stores, per user, a list of favorite items, which is created as a single hidden list per workspace when the Feature is enabled.

·         A custom menu item that is attached to all lists, called "Add to Favorites," which adds an item to the Favorites list.

·         A Web Part that implements usage and link tracking to display the user’s top 10 favorites at the top.

Each element of the Feature, by itself, may not be very useful, but when you enable the Feature on a site, all these elements add up to a complete solution. (WSS SDK)

Regards,

JERRY

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s