Sunday, February 21, 2010

Deploying List Definition as a Feature

In this blog post, I am going to talk about how to develop a custom list definition and deploying it as a feature in SharePoint.

Typically a custom list definition contains three xml files

  • Feature.xml
  • ElementsManifest.xml
  • Schema.xml

Now I’ll try to elaborate about each xml file:

Feature.XML This file registers the list template. This file specifies title, ID, scope of the feature and location of elementsmanifest file.

Typically a feature.xml file will be like this.

featureXML

ElementsManifest.xml This file adds the list template to the Create Page file that identifies the list template and specifies information to display on the Create Page. This file need not be with the same name. Whatever name you give, the same has to be mentioned in the feature.xml file. Give it a Type value that is above 10000 and different from any other custom list definitions used in your deployment and can be like this.

elementXML

Schema.xml This file defines the list schema, which includes content type associations, field and view definitions, and form and toolbar references. This file has to be in a sub folder under which list definition is created and the name of the sub folder has to be the same name as that assigned to the list template in the previous step, for example, SimpleList. Schema.xml is the file where we can mention, column details, views, etc.

I am not giving screen shot for schema.xml because recommended approach for creating a schema.xml file is take a copy of schema.xml from SharePoint 12 hive folder and customize it per your needs. This can be located at

12\TEMPLATE\FEATURES\CustomList\CustList

All IDs has to be GUIDs which you can create using a GUID builder such as one provided in Visual Studio.

Now all set to deploy a List definition feature. To deploy this, you can use a 3rd party utility which copies all these files in feature folder or you can do it manually. I’ve used codeplex tool WSP Builder to make the list definition and deploy. This can be downloaded from http://www.codeplex.com/wspbuilder . I’ll mention steps to deploy list definition manually.

Copy the entire folder in features folder of SharePoint. Typically this folder can be located in “12\TEMPLATE\ “. Once folder is copied run following command from BIn folder of SharePoint (12\BIN).

stsadm –o installfeature –name <name of the folder>

Once this command is successful, feature is ready in all the sites and ready to activate. You can browse to site settings of a site in which you want to activate the feature or execute the below command

stsadm -o activatefeature -name <name of the feature> -url <site URL>

That’s it.

Summary:

In this blog post, we have learned how to create a custom list definition, deploying it as a feature.

Viewers are welcome with questions.

 

Regards,

Sudhakar Bulli