Create Custom Lists in CAML based on existing List Templates
As a developer you can create your own custom lists using CAML. When deployed using a solution, the new lists are created when the feature is activated. You can create all types of lists and document libraries based on the standard SharePoint templates defined in the ONET.xml. In this section you will find a detailed explanation on how to create different types of lists and document libraries.
Introduction
If you want to deploy a custom list based on one of the available list templates, you have to create an elements file with only a ListInstance element in it. This ListInstance element must be enclosed in a Elements root element:
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ListInstance Title="My custom list" FeatureId="00BFEA71-DE22-43B2-A848-C05709900100" TemplateType="100" Id="MyCustomList" Description="Simple custom list sample." Url="Lists/MyCustomList" OnQuickLaunch="true" RootWebOnly="false" />
</Elements>
You can define a list instance based on existing list templates. The FeatureId value must correspond to that of the list definition on which you base your list instance. (So this is not the ID of your feature, as so many people think). The IDs of the available list templates can be found in the feature files making up the list templates. The template IDs are defined in the Type attribute of the ListTemplate element and the feature ID can be found in the Id attribute of the Feature element. I listed the possible values for the FeatureId and TemplateType attributes in the table below.
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 list is created when the feature is activated.
The following piece of CAML is the definition of the standard custom list template, on which you can base your own list instances. 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>
The following table lists all available list templates with their template type id and their corresponding feature id:
Type of list | TemplateType | 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 |
Publishing Pages | 850 | 22A9EF51-737B-4ff2-9346-694633FE4416 |
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 |
Following sections will explain how to create the different types of list instances in CAML.
Creating a list instance based on the generic list
You can define a list instance based on the generic list.
<ListInstance FeatureId="00BFEA71-DE22-43B2-A848-C05709900100" Title="Mars Moons" Description="List of moons of the planet Mars." Id="10001" TemplateType="100" OnQuickLaunch = "TRUE" Url="Lists/MarsMoons">
Important attributes of the ListInstance element are:
- Id: This is the internal name for the new list instance
- FeatureId: This is the ID of the feature in which the base list template is defined
- TemplateType: this is the template type id on which the new list instance will be based. A list of all standard list templates can be found below.
- Title: this is the display name for the new list instance
- Url: Returns the site-relative URL at which to place the list
- OnQuickLaunch: makes the new list instance accessible from the Quick Launch
- RootWebOnly: this boolean indicates whether the list can be created only on the root web or also on a sub web.
This creates a list with the standard set of fields like Title, ID, Created, Created By, Modified and Modified By. If you want extra fields on your list, you will first have to define a custom list definition based on the generic list and then create a list instance based on that new list definition. See my page on Creating custom list definitions for more information.
You can also populate the list with initial data by using the <Data> element. Within that <Data> element you need to specify a <Rows> element, that on its turn need to contain one or more <Row> elements. Each column that need to contain data must be specified with the <Field> element. The Name attribute must specify the internal name of the field.
<ListInstance FeatureId="00BFEA71-DE22-43B2-A848-C05709900100" Title="Mars Moons" Description="List of moons of the planet Mars." Id="10001" TemplateType="100" OnQuickLaunch = "TRUE" Url="Lists/MarsMoons"> <Data> <Rows> <Row><Field Name="Title">Phobos</Field></Row> <Row><Field Name="Title">Demeios</Field></Row> </Rows> </Data> </ListInstance>
Creating a list instance based on the standard document library
You can define a list instance based on the standard document library.
<ListInstance Title="My walkthroughs" FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" TemplateType="101" Id="MyWalkthroughs" Description="Document library storing my walkthroughs documentation." Url="MyWalkthroughs" OnQuickLaunch="true" RootWebOnly="false" DocumentTemplate ="100"/>
This creates a document library where the user can upload any type of document. If you want to add extra columns, you will have to define a custom list definition based on this type of list.
Important detail to note here is the DocumentTemplate element. The value specifies which type of documents are expected to be created or added to this document library. Following table lists the other standard document templates that can be used. The IDs can be found in the different ONET.XML files of the different site templates available in SharePoint:
Document template | DocumentTemplate |
None | 100 |
Microsoft Office Word 97-2003 document (.doc) | 101 |
Microsoft Office Excel 97-2003 spreadsheet (.xls) | 103 |
Microsoft Office Powerpoint 97-2003 presentation (.ppt) | 104 |
Microsoft Office Word 2007 document (.dotx) | 121 |
Microsoft Office Excel 2007 spreadsheet (.xlsx) | 122 |
Microsoft Office Powerpoint 2007 presentations (.pptx) | 123 |
Microsoft Office OneNote | 111 |
Microsoft Office SharePoint Designer web page | 102 |
Basic Page | 105 |
Web Part Page | 106 |
Creating a list based on a document library for Word 97-2003 documents
Using ListInstance you can also create a document library.
<ListInstance Title="My walkthroughs" FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" TemplateType="101" Id="MyWalkthroughs" Description="Document library storing my walkthroughs documentation." Url="MyWalkthroughs" OnQuickLaunch="true" RootWebOnly="false" DocumentTemplate ="101"/>
When the user then clicks the New button in the AllItems view, a new Word 97 compatible document will open, based on the standard template.doc file.
Creating a list based on a document library for Word 2007 documents
Using ListInstance you can also create a document library for Word 2007 documents:
<ListInstance Title="My walkthroughs" FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" TemplateType="101" Id="MyWalkthroughs" Description="Document library storing my walkthroughs documentation." Url="MyWalkthroughs" OnQuickLaunch="true" RootWebOnly="false" DocumentTemplate ="121"/>
If the user clicks the New button in the AllItems view, a new Word 2007 compatible document will open, based on the standard template.dotx file. If you want the user to use another Word 2007 template you have to define a content type and bind that content type to the list instance. First create the content type:
<ContentType ID="0x010100B31569E07DF64988A730D33E2B0451D2" Name="Walkthrough Document" Group="BPoint"> <Folder TargetName="_cts/Walkthrough Document" /> <DocumentTemplate TargetName="_cts/Walkthrough Document/WalkthroughTemplate.docx" /> </ContentType>
You also have to specify a Module element to deploy the word document:
<Module Name="Walkthrough Document" SetupPath="Features\BPoint List Instances" Path="" Url="_cts/Walkthrough Document" RootWebOnly="TRUE"> <File Url="WalkthroughTemplate.docx" /> </Module>
After definition of the ListInstance element, you have to bind the new content type to the list by using a ContentTypeBinding element. This element requires the following attributes
- ContentTypeId, which is the content type id of the new content type
- ListUrl, which is the Url of the newly created document library
<ContentTypeBinding ContentTypeId="0x010100B31569E07DF64988A730D33E2B0451D2" ListUrl="MyWalkthroughs"/>
Don’t forget to add a ElementFile element to the feature definition:
Feature Id="{E006B9CD-0F47-4a8c-BAF6-583177F2AABF}" Title="BPoint Walkthroughs List Instances Feature" Description="This feature creates all possible types of list instances." Version="12.0.0.0" Hidden="FALSE" Scope="Site" DefaultResourceFile="core" ImageUrl ="BPoint\BPoint.png" xmlns="http://schemas.microsoft.com/sharepoint/"> <ElementManifests> <!-- A generic custom list --> <ElementManifest Location="contenttype.xml"/> <ElementManifest Location="doclib2007.xml"/> <ElementFile Location="Documents\WalkthroughTemplate.docx"/> </ElementManifests> </Feature>
Creating a list based on a document library for Excel 2007 documents
To create a document library based on a blank Excel 2007 spreadsheet:
<ListInstance Title="My spreadsheets" FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" TemplateType="101" Id="MySpreadsheets" Description="Document library storing my Excel 2007 files." Url="MySpreadsheets" OnQuickLaunch="true" RootWebOnly="false" DocumentTemplate ="122" />
Creating a list based on a document library for Powerpoint 97-2003 documents
To create a document library based on a blank Powerpoint 2003 presentation:
<ListInstance Title="My powerpoints" FeatureId="00BFEA71-E717-4E80-AA17-D0C71B360101" TemplateType="101" Id="MyPowerpoints" Description="Document library storing my Powerpoint 2003 files." Url="MyPowerpoints" OnQuickLaunch="true" RootWebOnly="false" DocumentTemplate ="104" />
Creating a list instance based on the standard Picture Library template
You can define a list instance based on the standard picture library template.
<ListInstance Title="My pictures" FeatureId="00BFEA71-52D4-45B3-B544-B1C71B620109" TemplateType="109" Id="MyPictures" Description="New picture library based on picture library template." Url="MyPictures" OnQuickLaunch="true" RootWebOnly="false" />
You can find an extensive example on Andrew Woodward’s blog.
Creating a list instance based on the standard Tasks list template
You can define a list instance based on the standard tasks list template.
<ListInstance Title="My tasks" FeatureId="00BFEA71-A83E-497E-9BA0-7A5C597D0107" TemplateType="107" Id="MyTasks" Description="New task list based on task list template." Url="MyTasks" OnQuickLaunch="true" RootWebOnly="false" />
Creating a list instance based on the standard Slide Library template
And on request, you can also define a list instance based on the standard slide library template.
<ListInstance Title="My slides" FeatureId="0BE49FE9-9BC9-409d-ABF9-702753BD878D" TemplateType="2001" Id="MySlides" Description="New slide library based on slide library template." Url="MySlides" OnQuickLaunch="true" RootWebOnly="false" />
If you want to provision slides to the slide library that will be created with this feature, you can add a <Module> element to the elements file:
<Module Name="Slides" Url="MySlides" Path=""> <File Url="Slide1.ppt" Type="GhostableInLibrary"> <Property Name="Presentation" Value="List Instances Overview" /> <Property Name="Description" Value="What type of list instances can be created?" /> </File> <File Url="Slide2.ppt" Type="GhostableInLibrary"> <Property Name="Presentation" Value="Create Custom List Instance" /> <Property Name="Description" Value="Create a list instance based on the generic list template." /> </File> <File Url="Slide3.ppt" Type="GhostableInLibrary"> <Property Name="Presentation" Value="Create Custom Slide Library Instance" /> <Property Name="Description" Value="Create a list instance based on the slide library template." /> </File> </Module>
HI,
Your post is awesome! it does what exactly I wanted to do! I was wondering if I want to add two document library list instance using feature, how would I do that? How can I add list instance twice and contenttypeBindig for each into one feature?
Please guide.
Comment by MDeveloper | July 29, 2009 |
Hi,
wonderfull info. How can I use CAML to add a button/link to a survey’s action menu, I have searched hi and low for info and I can find tons of info on lists but nothing on a survey. I understand that surveys are a special kind of list, but does that specialty mean they don’t need to be documented? hummm….
Anywho: any help would be greatly appreciated…
thanks
Comment by carlos rodriguez | August 26, 2009 |
Hi
I am trying to get a custom list provisioned. But everytime a press the activate feature I get the following error.
Cannot complete this action.
Please try again. at Microsoft.SharePoint.Library.SPRequestInternalClass.CreateList(String bstrWebUrl, String bstrTitle, String bstrDescription, String bstrListUrl, String bstrFeatureId, Int32 lTemplateID, String bstrDocTemplateType, ListQuickLaunchOptions qlOpt)
at Microsoft.SharePoint.Library.SPRequest.CreateList(String bstrWebUrl, String bstrTitle, String bstrDescription, String bstrListUrl, String bstrFeatureId, Int32 lTemplateID, String bstrDocTemplateType, ListQuickLaunchOptions qlOpt)
Troubleshoot issues with Windows SharePoint Services.
This is my feature XML:
This is the instance
Local News
Weather
Sports
Can you see anything wrong with it, I have tried it for days now.
Thank you
Bedankt
Jan
Comment by jan vercauteren | October 5, 2009 |
Hi Jan,
Your xml is not visible in the blog post. You can send me your code to karinebosch@hotmail.com and I’ll try to help you out.
Greetz,
Karine
Comment by Karine Bosch | October 5, 2009 |
Hi Karine
I just found the solution.
Apperently you have to keep the featureID of the customlist if you want to provision a list from it in a ListInstance. I had replaced it with the feature ID of the feature I was developing.
Its stupid that I lost 3 days with it but on the other hand, I’ll never make that mistake again.
Anyway, thank you for the quick reply.
Kindest regards
Jan Vercauteren
Comment by jan vercauteren | October 5, 2009
Hi Jan,
Glad you found out. I will mention it more clearly in the post so that others will not make the same mistake.
Greetz,
Karine
Comment by Karine Bosch | October 5, 2009 |
You are my hero, one thing I dont quite understand. I have created a custom definition based on the document library template that has multiple content types- each with thier own template. I have installed it as a feature and I am able to create the library, all the content types are listed, but when I try to create the new doc, it cannot locate the template. If I update the content type, it will work, but this would mean that after anyone creates a library – we would need to update the parent content types every time for it to work.
Comment by Kyle Bakker | December 28, 2009 |
I neglected to set the comment to notify me when it is replied to- can you reply to this comment instead???
You are my hero, one thing I dont quite understand. I have created a custom definition based on the document library template that has multiple content types- each with thier own template. I have installed it as a feature and I am able to create the library, all the content types are listed, but when I try to create the new doc, it cannot locate the template. If I update the content type, it will work, but this would mean that after anyone creates a library – we would need to update the parent content types every time for it to work.
Comment by Kyle Bakker | December 28, 2009 |
Hi Kyle,
I’m pretty sure it works this way. You must have made a small typo somewhere in the CAML.
Karine
Comment by Karine Bosch | December 30, 2009 |
I have followed the example through, but I have obviously missed something because although I can deploy successfully (using VseWss), when I try to create a site collection, I get the error
Specified argument was out of the range of valid values.
Parameter name: ContentTypeId
What I did is create a new blank site definition, added a new content type pointing at my own Word document which I want to use as the template when adding a new item to the list, and add a Module to deploy the said document. Then I added a list definition with an instance and hooked it all up using your example.
I know it’s a bit cheeky, but do you have a simple project that I can examine to see where I have gone wrong?
Thanks, Paul
Comment by Paul Gregory | January 21, 2010 |
Hi Paul,
I saw your question on the forum but I haven’t had time to generate a sample at the moment.I have no code sample at hand for your specific problem, but if it can wait till tomorrow, I’ll try to generate one tomorrow.
But try one thing first: it is possible the value of the ListUrl attribute is not correct. Try to specify:
Karine
Comment by Karine Bosch | January 21, 2010 |
Hi Paul,
I took a look at your code on the forum, and if you don’t want to create additional columns in your content type, you can follow the sample as explained under the section “Creating a list based on a document library for Word 2007 documents” in this page. You only need a if you need additional columns of the content type in your list.
Comment by Karine Bosch | January 21, 2010 |
Karine,
Yes we do want additional columns, we want to capture data from the review process.
I thought the URL should be the same throughtout. I have to admit that I am not sure if I really understand the URL, I am only a novice with SharePoint. I will do a bit more research on this in case I have done something wrong.
Thanks for your help.
Paul
Comment by Paul Gregory | January 22, 2010 |
Hi Paul,
I will try to write a sample of a content type with extra columns and a doc template. I’ll post it on my blog as soon as I have some spare time.
Karine
Comment by Karine Bosch | January 22, 2010
Hi Karina,
Nice samples of custom lists.
A sample of a contenttype with extra column and document template would be nice.
I’m trying to add more than one contenttype with extra columns to a document library (for days), looks good on first sight, but when i create a new word 2003 document based on one of the custom contenttypes and then save it, i see all the extra columns of all my contenttypes in the property dialogbox of Word 2003 and not the dropdown for the contenttype. It’s a mess.
When i upload or edit a document (editform.aspx) it works fine, with a dropdownbox for the contenttype and the extra column of the selected contenttype.
Do you have any idea what’s wrong that causes the Word dialogbox not to function properly?
Comment by Andre | June 28, 2010
I am facing an issue when i add an instance in a site,i have 28 content types are there and more than half of them are not working in the listinstnace. Interestingly when i create document library manually my all the 28 content types types are opening with the associated files.
Comment by Manu | April 1, 2010 |
I’m not sure if I understand:
– you have 28 content types that you associate with a list using and
– when you verify the list settings page, you only see half of them
– when you try to create a new item on that same list, you can choose from your 28 content types
Is this the description of your problem?
Karine
Comment by Karine Bosch | April 2, 2010 |
i didnt see mention of necessity of including elements.xml in manifest/ddf, but otherwise, great article!
Thanks for posting it.
-Ron
Comment by ron | April 16, 2010 |
Hi Andre,
Take a look at this post: https://karinebosch.wordpress.com/walkthroughs/event-receivers-walkthrough5/
It contains an example on how to create a content type with extra columns and a custom doucment template.
At the moment I have no explanation for your problem with the Word dialog box. I’ll come back to you if I find an answer for this.
Karine
Comment by Karine Bosch | July 24, 2010 |
[…] Blog von Karine Bosch […]
Pingback by How to: SharePoint-Liste über schema.xml erzeugen - Oliver Wirkus - SharePointCommunity | September 20, 2010 |
there may be a typo in the table of List Templates above. In my environment the discussion list (type 108) is defined in feature 8b01f0a1-ec90-4ae4-af2a-fd2d62a78c86.
Comment by russell | October 12, 2010 |
That’s weird, I double-checked and in two different environments and it is feature ID 00BFEA71-6A49-43FA-B535-D15C05500108.
Karine
Comment by Karine Bosch | October 14, 2010 |
this is an excellent post.
how can I deploy my list with a custom view on the same list?
Comment by megan | June 22, 2011 |
[…] copyright from : Karine Bosch’s Blog […]
Pingback by Create Custom Lists in CAML based on existing List Templates « Developer blogs | September 15, 2011 |
Please help on following,
I have xml web service and it pulls data from oracle database but they data is dynamic,
my requiremnet is who syncronize the data with sharepoint list.\
Comment by abdul | November 11, 2011 |
Abdul,
You will have more luck if you place this question on the MSDN forum.
Kind regards,
Comment by Karine Bosch | November 11, 2011 |
Hello there, just became aware of your blog through Google, and found that it’s really informative. I’m gonna watch out for brussels.
I’ll appreciate if you continue this in future. Lots of people will be benefited from your writing. Cheers!
Comment by Jared | February 16, 2013 |
[…] Create Custom Lists in CAML based on existing List Templates « Karine Bosch’s Blog […]
Pingback by Resources: SharePoint List(s), List field(s) | lionadi | March 18, 2013 |
[…] This one is extracted from http://joelblogs.co.uk/2011/06/16/sharepoint-2010-base-types-list-template-and-definition-ids-and-content-types-ids/ and https://karinebosch.wordpress.com/walkthroughs/create-custom-lists-in-caml-based-on-existing-list-tem… […]
Pingback by Quick reference of SharePoint list and document library template ID’s | Sharath on SharePoint | September 7, 2013 |
[…] Standard List Definition (found here, probably also on MSDN: https://karinebosch.wordpress.com/walkthroughs/create-custom-lists-in-caml-based-on-existing-list-tem…😉 […]
Pingback by Add ListInstance via Powershell | Technology & Programming | November 20, 2013 |