Export (0) Print
Expand All

How to: Create a Custom List Definition

Windows SharePoint Services 3

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

This task demonstrates how to create a custom list template feature and add it to the selection of lists available for creating on the Create Page. Adding a custom list feature requires that you provide at least the following three files:

  • Feature.xml registers the list template.

  • Elements.xml adds the list template to the Create Page.

  • Schema.xml defines the list schema, which includes content type associations, field and view definitions, and form and toolbar references.

To add a custom list definition to a Web site

  1. Create a folder in Local_Drive:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATES\FEATURES and give it an appropriate name, such as SimpleListFeature.

  2. In the new folder create a Feature.xml file that specifies the title, ID, and scope for the Feature, as well as the location of an Elements.xml file, such as follows:

      Title="Simple List Feature" 
        <ElementManifest Location="Elements.xml" />
  3. To replace the GUID placeholder in the previous Id attribute, generate a GUID by running guidgen.exe, located in Local_Drive:\Program Files\Microsoft Visual Studio 8\Common7\Tools.

  4. In the new folder create an Elements.xml file that identifies the list template and specifies information to display on the Create Page. Give it a Type value that is above 10000 and different from any other custom list definitions used in your deployment:

        DisplayName="Simple List" 
        Description="This is my simple list." 
        SecurityBits="11" />
  5. Create a subfolder that has the same name as that assigned to the list template in the previous step, for example, SimpleList.

  6. Create a Schema.xml file in the new subfolder to define the list. You can copy and modify the Schema.xml file of an existing list Feature to define special fields for a custom list definition.

  7. At a command prompt, type the following commands to install the Feature in the deployment, and then activate the Feature on a specified subsite.

       a. stsadm -o installfeature -filename SimpleListFeature\Feature.xml
       b. stsadm -o activatefeature -name SimpleListFeature -url http://Server/Site/Subsite
  8. To test the new Feature, navigate to the Create Page and create a list through the template.

Define any custom fields that are required for your list near the beginning of the Schema.xml file. The following example, which copies and modifies the Schema.xml file of the default CustomList Feature, defines a special Choice field for the SimpleList Feature and adds this field to the Item content type so that the field is displayed in item forms.

To customize the Item content type definition, find the following content type declaration near the beginning of your copied Schema.xml file:

<ContentTypeRef ID="0x01">
  <Folder TargetName="Item" />

Replace this content type declaration with the Item content type definition whose ID equals 0X01 in the ctypeswss.xml file that is located at C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\ctypes.

Add a reference for your custom field to the content type definition, which in this example is called FavoriteColor. Also include the default Folder element to specify the resource folder for the content type. Create a unique ID for your content type as described in Content Type IDs. Use guidgen.exe as describe previously in step 3 to create GUIDs for the content type ID and for the field reference.

<List Name="SimpleList" Title="Simple List" BaseType="0" Direction="" Url="">

  <!--Copy the referenced ContentType definition from ctypeswss.xml.-->
        Name="FavoriteColor Item"
        Description="Favorite color item content type."

          <!--Add a field reference for the custom field.-->

          <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
            <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">

        <!--Include the relative folder path for the content type resource folder.-->
          TargetName="Item" />

        ID="0x0120" />

In the empty Fields tag that follows the ContentTypes section of Schema.xml, add a field definition for the FavoriteColor Choice field, as follows:

        DisplayName="Favorite Color">

Add a reference to the custom field in the ViewFields section of a view definition so that the field is displayed in the view. The following example adds a FavoriteColor field reference to the standard all items view.

  <FieldRef Name="Attachments"/>
  <FieldRef Name="LinkTitle"/>
  <FieldRef Name="FavoriteColor"/>
© 2014 Microsoft