Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
General Reference
 How to: Create a Custom List Defini...

  Switch on low bandwidth view
Community Content
In this section
Statistics Annotations (0)
How to: Create a Custom List Definition

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.

Procedures

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:

    <Feature 
      Title="Simple List Feature" 
      Id="80E23615-3145-4f43-BD5E-8524C02BD6CD" 
      Scope="Web" 
      xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests>
        <ElementManifest Location="Elements.xml" />
      </ElementManifests>
    </Feature>
  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:

    <Elements 
      xmlns="http://schemas.microsoft.com/sharepoint/">
      <ListTemplate 
        Name="SimpleList" 
        DisplayName="Simple List" 
        Type="10001" 
        Description="This is my simple list." 
        BaseType="0" 
        OnQuickLaunch="FALSE" 
        SecurityBits="11" />
    </Elements>
  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.

Schema.xml File

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" />
</ContentTypeRef>

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.

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

  <!--Copy the referenced ContentType definition from ctypeswss.xml.-->
      <ContentType 
        ID="0x010099FE4F3ACD494e30A36693F9EE65BAF2"
        Name="FavoriteColor Item"
        Group="$Resources:List_Content_Types"
        Description="Favorite color item content type."
        Version="0">
        <FieldRefs>
          <FieldRef 
            ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" 
            Name="Title" 
            Required="TRUE" 
            ShowInNewForm="TRUE" 
            ShowInEditForm="TRUE"/> 

          <!--Add a field reference for the custom field.-->
          <FieldRef
            ID="{AD22016D-BC8B-4631-A0A3-5E84C6CFA7EC}" 
            Name="FavoriteColor" 
            Required="TRUE" 
            ShowInNewForm="TRUE" 
            ShowInEditForm="TRUE"/>

        </FieldRefs>
        <XmlDocuments>
          <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
            <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
              <Display>ListForm</Display>
              <Edit>ListForm</Edit>
              <New>ListForm</New>
            </FormTemplates>
          </XmlDocument>
        </XmlDocuments>

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

      <ContentTypeRef 
        ID="0x0120" />
    </ContentTypes>

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

Xml
    <Fields>
      <Field 
        Type="Choice" 
        Name="FavoriteColor" 
        DisplayName="Favorite Color">
        <CHOICES>
          <CHOICE>Red</CHOICE>
          <CHOICE>Green</CHOICE>
          <CHOICE>Blue</CHOICE>
        </CHOICES>
      </Field>
    </Fields>
    <Views>
      ...

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.

Xml
<ViewFields>
  <FieldRef Name="Attachments"/>
  <FieldRef Name="LinkTitle"/>
  <FieldRef Name="FavoriteColor"/>
</ViewFields>

See Also

Community Content   What is Community Content?
Add new content RSS  Annotations
Extra step required to add a new column in a custom list definition      jorisp   |   Edit   |   Show History

I wrote a blog post which adds an extra step which is required to display the new column in the new and edit form - for more information take a look - http://jopx.blogspot.com/2007/05/sharepoint-2007-how-to-create-custom.html

Extra steps required for custom list definition      IslandG   |   Edit   |   Show History

Another good article for making sure that the new columns appear in the new and edit form.

http://blogs.provoke.co.nz/Ari/archive/2007/04/18/creating-a-custom-sharepoint-2007-list-definition.aspx

Missing reference in Elements.xml      Erik Bo   |   Edit   |   Show History

it should also be noted that you have to put a reference to sharepoint in the Elements.xml. Id est:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

Tags What's this?: Add a tag
Flag as ContentBug
Error after creating custom list in sharepoint      P.Keijzers ... MollyBos - MSFT   |   Edit   |   Show History

i have a problem with this when i select create and select the list i get a error if i look in the event log 2 things i see access denied for the hosts file and i see a runtimefilter error

does anybody have a idea in the rigth direction?

[MollyBos - MSFT] Please post questions to the newsgroups or forums. Try the Sharepoint Development forum for this one: http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.sharepoint.development_and_programming.

Two ways to achieve a custom list definition in a feature      MOSSuMS   |   Edit   |   Show History

I built custom list definitions in a feature (with visible fields!), based on the generic list, in two ways.

The first is quick and easy, but is less flexible so the result might not be exactly what you want. The second can give a cleaner result, but is a lot more involved.

The approaches followed were;

1. Use the SharePoint 3 Extensions for VS 2005 http://www.microsoft.com/downloads/details.aspx?FamilyId=3E1DCCCD-1CCA-433A-BB4D-97B96BF7AB63&displaylang=en - I'd go for this (at least as your starting point) if you need customisation such as different forms - or,

2. Read through the blogs above and trial and error it yourself! I did that and have documented my process, for the most basic custom list (no forms or custom content types), at: http://www.sharepointblogs.com/mossms/archive/2008/03/10/custom-list-feature.aspx .

In approach 2 there are quite a few steps to follow to get fields to show, nobody (outside of MS?) is 100% sure which are really required and it is easy to miss a step or make a mistake! As everyone wants a slightly different end result I'd get it working in the most basic form first as above, then only add and test small incremental changes.

Hope this saves someone else the pain involved in getting it right!

<a href="http://www.sharepointblogs.com/mossms">http://www.sharepointblogs.com/mossms</a>

Must change the list name in schema.xml      Gustavo Frederico   |   Edit   |   Show History
The text makes the suggestion to copy a schema.xml, but does not instruct you to change the list name. The example has the modified name.
<List Name="SimpleList" Title="Simple List" BaseType="0" Direction="" Url="">

If one does not change the list name, the following error may occur:

"One or more field types are not installed properly. Go to the list settings page to delete these fields."
Doesn't this promote bad practice?      Jarno Leikas   |   Edit   |   Show History
This method doesn't use site content types (ContentTypeRef's), but instead it defines the content type directly on the list schema. A better practice (in my opinion) is to define content types separately and just reference them on lists. This allows for centralized management of content types.

As far as I've understood, referencing site content types does, however, add an undesireable side-effect: All fields from your content types that are included in the <ViewFields> element must be redefined in the <Fields> element, effectively doubling the already cumbersome process.
ListTemplate IDs only have to be Unique PER FEATURE      Andy Burns   |   Edit   |   Show History
"Give it a Type value that is above 10000 and different from any other custom list definitions used in your deployment"

This is wrong and directly contradicts http://msdn.microsoft.com/en-us/library/ms462947.aspx where it says:

"This identifier must be unique within the feature, but need not be unique across all feature definitions or site definitions."

Certain functionality (such as thumbnailing in a custom Picture Library is dependent on the list template having an ID of 109, irrespective of the feature that it is defined in.
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker