Sep 19, 2009

To add event handler as a feature

Steps required to install master page as a feature.

There are two important files while creating the feature.
1) Feature.xml and Element.xml
Feature.xml tells the attributes like FeatureId,title ,scope and the location of the element file
Element.xml is the actual file that tells what this feature is actually doing.

2) Open Visual studio
3) Open a new project and select Class library type project
4) Right Click on the project name and new xml file and name it as feature.xml
5) Create a folder with name MasterPages which contains the master page

Feature.xml

<Feature Id=”95F25D4A-D256-4158-96FE-010F599149CC”

xmlns=http://schemas.microsoft.com/sharepoint/

Title=”Demo Master Page”

Scope=”Site” Version=”1.0.0.0″ Hidden=”FALSE” Description=”This Feature contains the demo master page”>

<ElementManifests>

<ElementManifest Location=”elements.xml” />

<ElementFile Location=”MasterPages\demomasterpage.master” />

</ElementManifests>

</Feature>

Now see the attributes required to create this featue.xml
Id :This is the unique id for each feature. This can be created
Goto Tools tab in the visual studio and select Create GUID and create a new GUiD
Title :To specify the name for the feature .Name of the Feature title and the name of the containing folder should be same
Description : To specify the description of the feature
Scope : This is very important property as this property defines the scope of the feature.
There are 4 types of scope :
a) Farm b) WebApplication c) Site d) Web
If scope is site then feature is installed at site collection level and it will be available to the root site and subsites below it.
If scope is web then the scope of the feature is web..

Hidden : This property specifies if this feature should be visible in the feature collection.This is important if user wants to activate the feature from the command line utility (i.e. stsad.exe)

Feature.xml specify the feature attributes but the
Now next element is the ElementManifests.
This contains two tags

This tells the location of the element file which contains the actual implementation of the feature

This tells the location of any other files that is required during the feature installation.In this scenario this the location of master page which is going to deployed
Here MasterPages is the name of the folder where it is stored(same as feature folder)
Element.xml

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>

<Module Name=”DemoMasterPage” Url=”_catalogs/masterpage” Path=”MasterPages” RootWebOnly=”FALSE”>

<File Url=”demomasterpage.master” Type=”GhostableInLibrary” />

</Module>

</Elements>

This file tells us what exactly has to be implemented
Inside the tag <Module set some attributes like
Name : , Url : this tells the location where master page has to be installed, Path: This gives the relative path of the master page file ,RootWebOnly : This property tells if this action has to be performed at only root web or it should be available to all the subsites.

<File tag gives information about the master page and it should be installed on the server
this tells SharePoint the name of the file it is going to put at the master page gallery. The type is “GhostableInLibrary” - this means the file is still going to be on the 12 hive and SharePoint is going to keep a Ghosted reference to the file. Please refer to article 3

http://sharepointmagazine.net/technical/customisation/developing-a-custom-master-page-master-pages-and-sharepoint-part-3-of-6 for more information about Ghosting. To install and activate the columns

Note : Copy the features folder in the 12/Template/Features folder in the file structure and then install and activate the feature

Through command line utility
Go to run and write cmd to open the command prompt
Go to the 12 hive folder
Command :
To install feature
Stsadm –o installfeature –name “” [-force]
To Activate feature
Stsadm –o activatefeature –name “” –url “” [-force]
Now the feature is installed and activated at a particular site collection. Go to the site settings and click on master pages there the newly installed master page will be available in the master page drop down.

Your Job is done !!!
Enjoy!!!

No comments:

Post a Comment