Tuesday, April 14, 2009

Creation of Site Columns using features

We can add a custom column to the sharepoint list or document library. Suppose if we have column called "Department", and if this need to be present in each and every list or document library. Instead of creating custom column for each and every list/document library, we create site column once and which can be used across all the lists/document libraries. This new feature available only in Moss 2007.

The simplest way of creating site column is navigate to SiteActions->Site Settings->Modify all site settings->click on Site columns under Galleries section, shows the list of all available site columns.

We can create a column with list of available data types.

Creating Site column with feature.

We can create the Site columns with feature.xml.
Create a folder called Moss.Features.SiteColumn
Create two xml files feature.xml and Element.xml as follows.
copy the below code in feature.xml

Id="{8C41689F-F45F-4b28-85B8-44C4B5197D02}"
Title="Moss.Features.SiteColumns"
Description="Custom MySite Columns"
Version="1.0.0.0"
Scope="Site"
Hidden="false"
xmlns="http://schemas.microsoft.com/sharepoint/">

Location="Elements.xml" />



Copy the below code in Elements.xml



ID="{4C67267C-B950-4cd4-8038-DEACA9EC2F74}"
Name="MyTitle"
Group="MyColumns"
DisplayName="MyTitle"
Type="Text"
Required="FALSE"
Sealed="TRUE"
MaxLength="250">



Note: here "Type" data type. You can mention any available datatypes.

Move this folder to 12hive feature folder, and install the feature as

stsadm -o installfeature -name Moss.Features.SiteColumns

Activate the feature as

stsadm -o activatefeature -name Moss.Features.SiteColumns -url http://servername:portno

This creates new site column called "MyTitle".
You can reuse this site columns for lists/document libraries.

stay glued for content types, Page Layouts, Master pages in my next posts.

Get back to me if you have any queries.
shreecanth@gmail.com

No comments: