How Do List Definitions Work?
List definitions are actually a part of site definitions. If you look under the standard STS site definition in SharePoint (C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\STS
), you'll find a LISTS
directory. This directory contains a set of list definitions. These list definitions are referenced from the XML\ONET.XML
file in the site definition. Under the <Project?>
node in the ONET.XML
file is a <ListTemplates>
node that contains a set of <ListTemplates>
nodes, each of which correspond with the directories in the LISTS
Connecting a list definition to a site definition is the process of creating the list definition, copying it to the LISTS directory, adding the appropriate <ListTemplate> node in the XML\ONET.XML file, performing an IISRESET, and finally creating a new site.
In order to walk through the examples in this article, it's advised that you create a new site definition to work with. The article "SharePoint Site Definitions: Why You Need Them and How to Use Them" shows you how to do this. Once you've done that, it's further advised that you create a new list definition based on one of the list definitions that already exist in the site definition. To create that new list definition, follow these steps:
- Copy one of the directories under the site defintion's LISTS directory to a new name. For example, copy CONTACTS to TESTCONT.
- Open the ONET.XML in the .\XML directory of the site definition.
- Locate the <ListTemplates> node.
- Copy the <ListTemplate> node underneath the <ListTemplates> node that corresponds to the list you copied. The Name attribute directly maps to the directory name that you copied (if you copied CONTACTS, it's the ninth node in the list).
- Paste a copy of this node at the end of the <ListTemplate> nodes.
- Change the Name attribute to match your new directory name. In the case of this example, TESTCONT.
- Change the DisplayName attribute to something descriptive. In this example, that might be "Test Contacts."
- Change the Type attribute to a unique number. In this case, 201 should work. The 200 series of numbers is unused so it's a good place to start with numbering your custom list definitions.
- Save the ONET.XML file.
- Reset IIS (Start>Run>IISRESET)
- Create a new site and verify that you can create a new list of type "Test Contacts."
Now that you've created new copies of a site definition and a list so that your changes won't break anything, it's time to dig into the heart of the list definition. Internally, a list definition consists of a SCHEMA.XML
file and a set of .aspx
pages that represent the display, new, update/edit, and default views for the list. These files are referred to in the SCHEMA.XML
so that, when the list is created, SharePoint creates links to these pages in the database.
The SCHEMA.XML has the basic format shown in Figure 1.
|Figure 1. The SCHEMA.XML File: This shows the SCHEMA.XML file's basic structure.|
SCHEMA.XML has two basic sections. The first section is the <MetaData> section. This is the definition for the list and the most commonly modified. The second section is the Data section. This allows you to automatically add data to the list when the list is created. This is useful for lists such as a project risks list that might have a set of risks that are common to every project. For instance, the risk of organizational changes and personal changes are common to every project. You might add these to the list by including the data in the SCHEMA.XML file.
In the <MetaData> section of the file, there are sections for the fields, the views, and the forms used by the list. This is where the heart lay of customizations for a list. In the following sections, you'll look at how to manage the appearance of the pages and to add a new field to the list.