Creating a List Definition

You can create a list definition by modifying two files within a site definition: the SCHEMA.XML file that applies to the list, and the ONET.XML file that applies to the site as a whole.

Warning  It is required that you create a custom site definition by copying an existing site definition, rather than modifying the original files installed with Windows SharePoint Services. Changes that you make to originally installed files may be overwritten when you install updates or service packs for Windows SharePoint Services, or when you upgrade an installation to the next product version. For information on creating a custom site definition, see Creating a Site Definition from an Existing Definition.

  • Copy the Custlist folder located in the Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\Site_Template_Name\LISTS directory.

  • Rename the new folder as appropriate for the list.

    The following example creates a list to organize shared commuting for employees, and so the folder is named COMMUTING.

  • Open the SCHEMA.XML file of the new list folder and create field definitions by adding Field elements within the empty Fields element in the opening MetaData element.

    Definitions added in the MetaData element specify the names and types of fields to use in the list. This example defines seven fields, including Text, Choice, Number, and Note fields. The Choice fields create drop-down lists for making selections.

    <Fields>
       <Field Name="LinkTitle" DisplayName="Driver" Required="TRUE"/>
       <Field Name="Title" DisplayName="Driver" Required="TRUE"/>
       <Field Name="ParkingLocation" Type="Choice" DisplayName="Park & Ride Location" Required="TRUE">
          <CHOICES>
             <CHOICE>Eastgate</CHOICE>
             <CHOICE>North Park</CHOICE>
             <CHOICE>South Terrace Center</CHOICE>
             <CHOICE>Lake Shores</CHOICE>
          </CHOICES>
       </Field>
       <Field Name="ToWork" Type="Choice" DisplayName="To Work" Required="TRUE">
          <CHOICES>
             <CHOICE>7am</CHOICE>
             <CHOICE>8am</CHOICE>
             <CHOICE>9am</CHOICE>
             <CHOICE>10am</CHOICE>
          </CHOICES>
       </Field>
       <Field Name="FromWork" Type="Choice" DisplayName="From Work" Required="TRUE">
          <CHOICES>
             <CHOICE>4pm</CHOICE>
             <CHOICE>5pm</CHOICE>
             <CHOICE>6pm</CHOICE>
             <CHOICE>7pm</CHOICE>
          </CHOICES>
       </Field>
       <Field Name="Capacity" Type="Number" DisplayName="Capacity" Required="TRUE"/>
       <Field Name="Preferences" Type="Note" DisplayName="Personal Preferences"/>
    </Fields>
    

    All fields except the last Note field require that users provide information in order to sign up.

  • After you define the fields, you must specify them as view fields in order for them to display in the list. To do this, search for the ViewFields element within the section of SCHEMA.XML that defines the All Items view and add field references, as follows:

    <ViewFields>
       <FieldRef Name="LinkTitle"></FieldRef>
       <FieldRef Name="ParkingLocation"></FieldRef>
       <FieldRef Name="ToWork"></FieldRef>
       <FieldRef Name="FromWork"></FieldRef>
       <FieldRef Name="Capacity"></FieldRef>
       <FieldRef Name="Preferences"></FieldRef>
    </ViewFields>
    
  • It is required that a custom list definition have a default description. Add a DefaultDescription element within the MetaData element of the SCHEMA.XML file, as follows:

    <DefaultDescription>
      Use this list to organize shared rides to and from work with others.
    </DefaultDescription>
    
  • To display the list as an option on the Create Page, you must specify the new list type within the ListTemplates element of the ONET.XML file for the site definition, located at Local_Drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\TEMPLATE\1033\[Site_Template_Name]\XML. To do this, find the ListTemplates element and add a ListTemplate element, as follows:

    <ListTemplate Name="COMMUTING" DisplayName="Shared Rides" Type="133" BaseType="0"
       OnQuickLaunch="FALSE" SecurityBits="12" Description="Save gas and enjoy the ride to work with co-workers."
       Image="_layouts/images/ittask.gif">
    </ListTemplate>
    

    The example specifies both the displayed and internal names, as well as an image and description to use on the Create Page. Since the list definition is based on a the Generic List type, the value of its BaseType attribute is set to 0.

    Important  The Name attribute must be set to the exact name of the new list folder. To identify the list, assign a numerical ID that is not being used elsewhere and that is less than 1000 to the Type attribute.

    The example sets the OnQuickLaunch attribute to FALSE. This attribute specifies whether the option to display the list in the Quick Launch area appears selected by default on the page for creating an instance of the list.

    The SecurityBits attribute specifies permissions for a list, where the first bit represents Read access and the second bit represents Write access. The bit for Read access contains one of two possible values: 1 allows all users Read access to all items, and 2 allows users Read access only to items they create. The bit for Write access contains one of three possible values: 1 allows all users to modify all items, 2 allows users to modify only items they create, and 4 prevents users from modifying the list. This example sets the security bits to 12, which prevents users from modifying the items of other users.

The new list list definition now appears on the Create Page and users can add lists to the Microsoft SharePoint site using the new definition.

For another example about creating custom lists, see Adding a Field to a Custom List.