Create Custom List Definitions in CAML
Introduction
As a developer you can create your own list definitions in SharePoint based on the different existing list templates. Best practice is to define them in XML and to deploy them as a feature. Your list definitions can range from very simple to very complex and can be defined in a wide range of flavors.
Your feature.xml file must reference the elements file:
<Feature Id="{22E8B537-52B1-4588-BF93-F5A20598E199}"
Title="My custom list definition feature"
Description="Feature defining a my custom list definition"
Scope="Site"
Hidden="FALSE"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="listtemplate.xml" />
</ElementManifests>
</Feature>
The following code is the definition of the custom list template. The CustomList.xml file can be found in the 12\TEMPLATE\FEATURES\CustomList\ListTemplates directory:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <ListTemplate Name="custlist" Type="100" BaseType="0" OnQuickLaunch="TRUE" SecurityBits="11" Sequence="410" DisplayName="$Resources:core,custList;" Description="$Resources:core,custList_Desc;" Image="/_layouts/images/itgen.gif"/> </Elements>
Important details to note are:
- FeatureId (optional): This is the ID of the feature in which the list template is defined
- BaseType (required): Specifies the base type, or default schema, for lists created using this template. See the table below for the 5 possibilities.
- Type: this is the template type on which the new list template is based. Se the table below for all base types of standard SharePoint list templates.
- DisplayName: the display name of the list template.
More details can be found in André Vala’s post.
The following table lists the 5 base types:
| Base Type | Description |
| 0 | Generic List |
| 1 | Document Library |
| 3 | Discussion List |
| 4 | Survey |
| 5 | Issue List |
The following table lists all available list templates with their template type id and their corresponding feature id:
| Type of list | TemplateId | FeatureId |
| Generic List | 100 | 00BFEA71-DE22-43B2-A848-C05709900100 |
| Document Library | 101 | 00BFEA71-E717-4E80-AA17-D0C71B360101 |
| Survey | 102 | 00BFEA71-EB8A-40B1-80C7-506BE7590102 |
| Links List | 103 | 00BFEA71-2062-426C-90BF-714C59600103 |
| Announcements List | 104 | 00BFEA71-D1CE-42de-9C63-A44004CE0104 |
| Contacts List | 105 | 00BFEA71-7E6D-4186-9BA8-C047AC750105 |
| Events List | 106 | 00BFEA71-EC85-4903-972D-EBE475780106 |
| Tasks List | 107 | 00BFEA71-A83E-497E-9BA0-7A5C597D0107 |
| Discussion List | 108 | 00BFEA71-6A49-43FA-B535-D15C05500108 |
| Picture Library | 109 | 00BFEA71-52D4-45B3-B544-B1C71B620109 |
| Data Sources | 110 | 00BFEA71-F381-423D-B9D1-DA7A54C50110 |
| Site template gallery | 111 | |
| User Information List | 112 | |
| Web Part gallery | 113 | |
| List Template gallery | 114 | |
| XML Form Library | 115 | 00BFEA71-1E1D-4562-B56A-F05371BB0115 |
| Master Pages gallery | 116 | |
| No-Code Workflows | 117 | 00BFEA71-F600-43F6-A895-40C0DE7B0117 |
| Custom Workflow Process | 118 | 00BFEA71-2D77-4A75-9FCA-76516689E21A |
| Wiki Page Library | 119 | 00BFEA71-C796-4402-9F2F-0EB9A6E71B18 |
| Grid List | 120 | 00BFEA71-3A1D-41D3-A0EE-651D11570120 |
| Data Connection Library | 130 | 00BFEA71-DBD7-4F72-B8CB-DA7AC0440130 |
| Workflow History | 140 | 00BFEA71-4EA5-48D4-A4AD-305CF7030140 |
| Gantt Task List | 150 | 00BFEA71-513D-4CA0-96C2-6A47775C0119 |
| Meeting Series List | 200 | |
| Meeting Agenda List | 201 | |
| Meeting Attendees List | 202 | |
| Meeting Decision List | 204 | |
| Meeting Objectives List | 207 | |
| Meeting Things to Bring List | 211 | |
| Meeting Workspace Pages List | 212 | |
| Blog Posts List | 301 | |
| Blog Comments List | 302 | |
| Blog Categories List | 303 | |
| Status Indicator (KPI) List | 432 | 7ED6CD55-B479-4EB7-A529-E99A24C10BD3 |
| Report Library | 433 | 6E53DD27-98F2-4AE5-85A0-E9A8EF4AA6DF |
| Issue Tracking List | 1100 | 00BFEA71-5932-4F9C-AD71-1557E5751100 |
| Administrator Tasks List | 1200 | |
| Translation Management Library | 1300 | 29D85C25-170C-4df9-A641-12DB0B9D4130 |
| Translation List | 1301 | 29D85C25-170C-4df9-A641-12DB0B9D4130 |
| Slide Library | 2100 | 0BE49FE9-9BC9-409d-ABF9-702753BD878D |
Creating a list definition based on a generic list
There is a good post of Andrew Connell that explains the basics so I won’t repeat them here.
Creating a list definition based on a document library
Step 1
As you can create a list definition based on a generic list, you can also create a custom defintion based on the standard document library. The best way is to base the new document library template on the existing template. Create a Visual Studio 2008 project and create the necessary folder infrastructure. Add a sub folder with f.e. the name Custom Document Library Template.
Step2
Locate the DocumentLibrary folder in the C:\Program Files\…\12\TEMPLATE\FEATURES directory and copy the files to the Custom Document Library Template folder in your Visual Studio 2008 project.
Step 3
The feature.xml file can be modified as follows:
<Feature Id="{C8880A81-8EF2-4037-90A5-022796A917C8}"
Title="Planet Document Library Template Feature"
Description="This feature demonstrates how you can define your own document library templates using CAML."
Scope="Site"
Version="1.0.0.0"
Hidden="FALSE"
ImageUrl ="BPoint\BPoint.png"
DefaultResourceFile="core"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="ListTemplates\DocumentLibrary.xml" />
<ElementFile Location="DocLib\schema.xml" />
<ElementFile Location="DocLib\EditDlg.htm" />
<ElementFile Location="DocLib\Repair.aspx" />
<ElementFile Location="DocLib\Upload.aspx" />
</ElementManifests>
</Feature>
Change the feature ID to a unique GUID and also the properties Title, Description.
Step 4
Find the documentlibrary.xml in the ListTemplates folder and open it.
<Elements Id="bc53ee2c-46b3-41ea-8deb-e75013c92eee" xmlns="http://schemas.microsoft.com/sharepoint/"> <ListTemplate Name="CustomDocLibTemplate" DisplayName="Custom Document Library Template" Description="Custom document library template." BaseType="1" Type="10100" OnQuickLaunch="TRUE" SecurityBits="11" Sequence="130" Image="/_layouts/images/itgen.gif" /> </Elements>
Change the values for the Name, DisplayName and Description attributes. Leave the BaseType to 1 as it indicates that you are building on the document library template.
Change also the value of the Type attribute. Custom list templates must have at least number 10000. When I create a custom document library template, I start by 101 and then add a sequence number like 00, 01, 02, etc.
The Sequence attribute indicates the order in which the template hyperlinks will appear on the Create page. Library templates all have a number between 100 and 199 and show up in utmost left section of the Create page. This code snippet has its Sequence attribute set to 130.Once the list template deployed, the hyperlink will appear below the Form Library template, as shown in the picture.

Step 5
Find the schema.xml in the DocLib sub folder and open it. Change the values for the Title and Url properties.
<List xmlns:ows="Microsoft SharePoint" Title="Custom Document Library" Direction="$Resources:Direction;" Url="Custom Document Library Template" BaseType="1" FolderCreation="false" EnableContentTypes="False" VersioningEnabled="false">
If you want don ‘t want your users to be able to create folders in your custom document library, you have to add the FolderCreation attribute and set it to true.
If you want document libraries based on this template to be version enabled, set the VersioningEnabled attribute to true.
You can also prevent users from making document libraries content type enabled by adding the attribute DisallowContentTypes and set its value to false.
Information on other possible attributes can be found here.
Now you are ready to deploy your custom document library template and start using it.
Creating a list definition based on a generic list using a custom content type
But if you want to have additional columns added to the document library you have to create the necessary site columns and a content type containing these columns, before these columns can be used in the document library template.
x
A side node on adding fields to the list template: when you need site columns based on the Lookup type, you will have to create the site columns programmatically. Read more about this in this blog post.

Regarding:
But if you want to have additional columns added to the document library you have to create the necessary site columns and a content type containing these columns, before these columns can be used in the document library template.
Can we do the above in the same VS Solution or do we need to do in seperate VS Solution?
I imagine you add reference in new DocLib List ContentTypeRef?
Been tearing my hair out trying to add ContentType directly in new DocLib definition
Yes, you can do that in the same VS solution.
Or you create different elements.xml files f.e. :
- sitecolumns.xml
- contenttypes.xml
- listdefinition.xml
And deploy the 3 files from within your feature.xml
Or you create 3 different features, but then you have to create ActivationDependencies in de different features.
Karine