Creating a SharePoint List Template using a Feature

Building on the last post about creating a content type, in this post we’ll create a custom list template which uses that content type and deploy it using a feature.

If you’ve ever taken a look at the schema definition file for a list template, you may baulk at it’s size and complexity, in fact you can ignore most of this, creating a custom list template turns out to be relatively straightforward.

A list template comprises 2 files;

  1. The list template.xml file
  2. The list template schema.xml file

Create the list template.xml file and add it to your feature manifest file;

<?xml version="1.0" encoding="utf-8"?>
<Elements Id="8f1d5d09-6834-40b7-b245-c62c0811596e" xmlns="">
	<ListTemplate Name="MyTestListTemplate" 
		  Image="/_layouts/images/itgen.gif" />

Note the Name and BaseType attributes, we will create a subfolder with the same name as the Name attribute and place the schema.xml file there. The BaseType attribute indicates the list type from which this list templates inherits which in this case is the basic custom list.
Add the listtemplate.xml file to the feature manifest;

<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="adc873b4-fe40-4169-8304-c9a1dd697c2b"
          Description="Description for MySiteTypes"
    <ElementManifest Location="sitecolumns.xml"/>
    <ElementManifest Location="mycontenttype.xml"/>
    <ElementManifest Location="listtemplate.xml"/>

Now for the schema.xml file, create a subfolder in your feature named “MyTestListTemplate” and in that folder create a new XML file called schema.xml.
To populate this file you have some options;

  1. Create it manually (take a look at the huge amount of CAML!!)
  2. Copy the base Custom List schema.xml file and modify it
  3. Craft the list/views etc in SharePoint using the UI and export the template using SharePoint Manager or the SharePoint Solution Generator

Using one of these methods you should then modify your schema.xml file as follows;

Change the Name, Title and URL attributes;

<List Name="TestList" Title="TestList" Description="" Direction="0" BaseType="0" 

The contenttypes section should contain only the content type(s) you’ve defined for this list;

		<ContentTypeRef ID="0x0100928100FAB05A4148BD6F4C8E6A716B40" />

To the Fields section add only the field definitions defined in the content types list in the above contenttypes section;

	<Field Type="Number" DisplayName="MyReference" Required="FALSE" Decimals="0" Commas="FALSE" Group="My Group" ID="{918BA6B8-60BC-417e-AEE5-F9E1A0A59144}" StaticName="MyReference" Name="MyReference" Customization="" SourceID="{6a05fd42-eda7-4fb7-9bfd-2a35ded20c24}" ColName="float1" RowOrdinal="0">
	<Field Type="Choice" DisplayName="MyType" Description="Description of MyType" Required="FALSE" Format="RadioButtons" FillInChoice="FALSE" Group="My Group" ID="{1FDC83BE-D596-45e2-9DD3-AD3338798784}" StaticName="MyType" Name="MyType" Customization="" SourceID="{6a05fd42-eda7-4fb7-9bfd-2a35ded20c24}" ColName="nvarchar3" RowOrdinal="0">
	<Field Type="Note" DisplayName="MyDetails" Description="Description of MyDetails" Required="FALSE" NumLines="5" RichText="FALSE" Sortable="FALSE" Group="My Group" ID="{AB31BEFA-A178-4a1e-B324-B73E9C15D5A8}" StaticName="MyDetails" Name="MyDetails" AllowHyperlink="TRUE" RichTextMode="Compatible" IsolateStyles="FALSE" AppendOnly="FALSE" Customization="" SourceID="{6a05fd42-eda7-4fb7-9bfd-2a35ded20c24}" ColName="ntext2" RowOrdinal="0">

Modify the ViewFields section of each View (there are 2 views defined by default, a HTML view and the AllItems view) to include the columns required;

		<FieldRef Name="Attachments" />
		<FieldRef Name="LinkTitle" />
		<FieldRef Name="MyReference" />
		<FieldRef Name="MyType" />
		<FieldRef Name="MyDetails" />

You might also want to use the LinkTitleNoMenu column which is a straight link column to the proprty page of the list item, rather than the LinkTitle column which includes the dropdown ECB menu.

If you have exported the schema.xml file using one of the methods mentioned, you should check that your View element(s) (except the view with BaseViewID of 0 zero) have the SetupPath attribute set correctly.

<View DefaultView="TRUE" 
      Type="HTML" DisplayName="All Items" Url="AllItems.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" 
      ImageUrl="/_layouts/images/DECISION.GIF" WebPartZoneID="Main">

Finally check that the Forms section is as follows;

      <Form Type="DisplayForm" Url="DispForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="EditForm" Url="EditForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />
      <Form Type="NewForm" Url="NewForm.aspx" SetupPath="pages\form.aspx" WebPartZoneID="Main" />

Build and Deploy the feature to your SharePoint site and activate the MySiteTypes feature.
The new “Test List” list template will now appear in the Custom Lists section of a sites Create page as shown.
You can now create a sample list based on this template.

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

2 thoughts on “Creating a SharePoint List Template using a Feature

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.