Create Custom List Templates 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 |
Publishing Pages Library | 850 | |
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 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.
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
Comment by Bill | November 3, 2009 |
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
Comment by Karine Bosch | November 3, 2009 |
Good Post, very helpfully. I’m trying to do the same thing but however for a wiki page library list. Any ideas on how to proceed with this.
Thanks
Aj
Comment by Aj | January 14, 2010 |
A Wiki Page Library is not defined as a normal document library. I found it in the ONET.XML of the Wiki site template.
I suggest you create a Wiki Page Library in a SharePoint site, define the extra columns you need and save it as a list template. An .stp file will be saved in the List Template Gallery from where you can download it. An .stp file is in fact a .cab file, so you can rename it to that extension. From there you can extract the manifest.xml and take a look at the rather complex CAML.
You will see that you have the element and the element where you can add the extra columns needed.
Greetz,
Karine
Comment by Karine Bosch | January 15, 2010 |
Thanks Karine, i’ll give that a go
Comment by Aj | January 15, 2010 |
How to add sub-folders to a custom document library in a site definition? I could add a straightforward level 1 folder thru onet.xml file by adding :
0x0120
1
Folder1
Folder1
But I am looking to add sub-folders as part of the site definition for example:
DocumentLibrary1
Folder1
SubFolder1
Any suggestions?
Comment by MMC | January 26, 2010 |
The xml tags could removed in the above comment. To create level 1 folder one could do it as below:
http://howtocode.blogspot.com/2007/04/moss-creating-folders-to-list-in.html
but how do we create sub-folders?
Comment by MMC | January 26, 2010 |
[…] element. I copied them verbatim here for my reference. The original post can be found here: https://karinebosch.wordpress.com/walkthroughs/create-custom-list-templates-in-caml/ Important details to note […]
Pingback by Alonso Robles » Blog Archive » Important Custom SharePoint List Template Notes - technology, academia, and other tidbits from the trenches of a boggled mind | March 17, 2010 |
Thank you !!!!
Comment by isa | March 22, 2010 |
I created custom document library with list type-40000 and base type ‘document library’ .. now if we retract and remove feature from farm.. all the custom libs stop workin as there list type 40000 not found. this make sense, is there a way to switch these existing custom lists back to type 101 which is out of box doc library list type.. ?
Comment by Kashish | May 15, 2010 |
Hi Kashish,
If all these lists were based on the 40000 template, then it is normal that they don’t work anymore.
You can always try to use the object model and try to change their base type programmatically.
Karine
Comment by Karine Bosch | May 16, 2010 |
Link broken at:
More details can be found in André Vala’s post.
Thanks,
~NN
Comment by NiceNix | September 13, 2010 |
It is really helpful
Thanks
Saumil
Comment by saumil | November 14, 2011 |
Regarding where you say “Change also the value of the Type attribute,” I believe it is not required and even not wise to change the type here. Some action items depend on the ServerTemplate/type, e.g. the “Connect to Outlook” depends on your list being of type 105 or some other base type. If your list template is not 105, e.g. for contacts, you will not see this action item. Furthermore, if you try to fix the list template and redeploy, all your existing lists will break with error “invalid list template.” So is it not advisable to set your type in your ListTemplate to one of the base types, e.g. 101, 105, etc.?
Comment by AWG | March 21, 2012 |
Hello Karine. I created a list based on the custom list with template ID -100 and saved the newly created list as template. My customized list template contains the same ID – 100. Is there a way to differentiate between the generic list with ID -100 and a list I have saved as a template?
Comment by Jennifer | June 12, 2012 |
Hi Jennifer,
You should use a different template id as it is demonstrated in step 4 of this blog post. The BaseType indicates from which type of list you want to inherit. In your case it is 0. Set the value of the Type attribute to a value higher than 10000.
Karine
Comment by Karine Bosch | June 13, 2012 |
[…] The first query option is the Lists element which requires a ServerTemplate attribute. The value should be an integer indicating the list server template. You can find a list of the standard server template IDs here. […]
Pingback by Caml Designer » Caml Designer 2010 | January 3, 2013 |
[…] The first query option is the Lists element which requires a ServerTemplate attribute. The value should be an integer indicating the list server template. You can find a list of the standard server template IDs here. […]
Pingback by CamlDesigner » CamlDesigner 2010 | April 27, 2013 |
Hi Karine,
Is there any option from which custom list template , a list is created ? I have a discussion form list in the site. I have to make sure that it is created by the one of the list template stored in Site Collection List template Gallary. Is there any way for this.
Please help.
Thanks.
Regards,
Nimisha
Comment by Nimisha | May 28, 2013 |
Hello Karine,
Thanks for your excellent article. I have a problem though which is based upon Comment 12 herein and would very much appreciate it if you would help. I have posted the issue here
http://social.msdn.microsoft.com/Forums/sharepoint/en-US/b322895b-9c1c-49b9-aaff-c8d1412243a3/connect-to-outlook-disabled-on-sps-2010-for-own-list-definitions?forum=sharepointdevelopmentprevious&prof=required
Maz
Comment by Maz | December 6, 2013 |