Create a SharePoint 2010 List Definition

In this article we will explain how to create a SharePoint 2010 List Definition using Visual Studio 2010.

Open Visual Studio 2010  then select "File" -> "New" -> "Project...".

Select the Visual C#  -> SharePoint 2010 --> List Definition project template.

Enter "MyTestList" in the Name TextBox and click on OK.

List Definition

In the SharePoint Configuration Wizard select "Deploy as farm solution" and click on "Next".

Next

Enter "MyTestList" in the What is the display name of the list definition? TextBox.

Select "Custom List" in the What is the type of the list definition? Drop-down box.

Custom List

In the Solution Explorer, expand ListInstance1 and open the Elements.XML file:

Solution Explorer

Within the ListInstance element change the Title attribute to MyTestList and change the TemplateType attribute to 10009.

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  3.   <ListInstance Title="MyTestList"  
  4.                 OnQuickLaunch="TRUE"  
  5.                 TemplateType="10009"  
  6.                 Url="Lists/MyTestList-ListInstance1"  
  7.                 Description=" My Test List Instance">  
  8.   </ListInstance>  
  9. </Elements> 

Now, open the Elements.xml file that is on the same level as ListDefinition1.

Within the ListTemplate element, change the Type attribute to “10009” and add the DisallowContentTypes=”FALSE” attribute, as shown below:

  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  3.     <!-- Do not change the value of the Name attribute below. If it does not match the folder name of the List Definition project item, an error will occur when the project is run. -->  
  4.     <ListTemplate  
  5.         Name="ListDefinition1"  
  6.         Type="10009"  
  7.         BaseType="0"  
  8.         DisallowContentTypes="FALSE"  
  9.         OnQuickLaunch="TRUE"  
  10.         SecurityBits="11"  
  11.         Sequence="410"  
  12.         DisplayName="MyTestList"  
  13.         Description="My Test List Definition"  
  14.         Image="/_layouts/images/itgen.png"/>  
  15. </Elements> 

Insert the following XML into the top of the Elements element in the Elements.xml file. This XML describes the MyTestList Item content type the list will store.

  1. <ContentType  
  2.       ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94"  
  3.       Name="My Test List"  
  4.       Group="Custom Content Types"  
  5.       Description="My Test List content type."  
  6.       Version="0">  
  7.       <FieldRefs>  
  8.         <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />  
  9.         <FieldRef ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" />  
  10.         <FieldRef ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}" />  
  11.         <FieldRef ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" />  
  12.       </FieldRefs>  
  13. </ContentType> 

Insert the following XML into the top of the Elements element in the Elements.xml file. This XML describes the Fields the MyTestList Item content type uses.

  1. <Field Type="Note" DisplayName="Title" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" StaticName="Title" Name="Title" Group="Custom Columns" />  
  2.    
  3.   <Field Type="Note" DisplayName="ID" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="ID" Name="ID" Group="Custom Columns" />  
  4.    
  5.   <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name" Name="Name" Group="Custom Columns" />  
  6.    
  7.   <Field Type="Text" DisplayName="Course" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="Course" Name="Course" Group="Custom Columns" /> 

In the Solution Explorer, open Schema.xml.

Add the EnableContentTypes=”TRUE” attribute to the List element inside of the Schema.xml file.

  1. <List xmlns:ows="Microsoft SharePoint" EnableContentTypes="TRUE" Title="MyTestList"   
  2.                        FolderCreation="FALSE" Direction="$Resources:Direction;"   
  3.                                  Url="Lists/MyTestList-ListDefinition1" BaseType="0"   
  4.                                xmlns="http://schemas.microsoft.com/sharepoint/"

Insert the following XML into the ContentTypes element in the schema.xml file. This XML describes the MyTestList Item content type this list will store.

  1. <ContentTypes>  
  2.       <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />  
  3.       <ContentTypeRef ID="0x01">  
  4.         <Folder TargetName="Item" />  
  5.       </ContentTypeRef>  
  6.       <ContentTypeRef ID="0x0120" />  
  7. </ContentTypes> 

Insert the following XML into the Fields element. This XML describes the fields the list will store. These are directly related to the fields in the Content Type we added in the previous step.

  1. <Fields>   
  2.       <Field Type="Note" DisplayName="Title" Required="FALSE" NumLines="6"   
  3. RichText="FALSE" Sortable="FALSE" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" StaticName="Title" Name="Title"Group="Custom Columns" />  
  4.    
  5.       <Field Type="Note" DisplayName="ID" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="ID" Name="ID" Group="Custom Columns" />  
  6.    
  7.       <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name" Name="Name" Group="Custom Columns" />  
  8.    
  9.       <Field Type="Text" DisplayName="City" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="City" Name="Course" Group="Custom Columns" />    
  10. </Fields> 

Insert the following XML into the ViewFields element in the 2nd view, BaseViewID="1":

  1. <ViewFields>  
  2.           <FieldRef Name="Attachments"></FieldRef>  
  3.           <FieldRef Name="LinkTitle"></FieldRef>  
  4.           <FieldRef Name="Title"></FieldRef>  
  5.           <FieldRef Name="ID"></FieldRef>  
  6.           <FieldRef Name="Name"></FieldRef>  
  7.           <FieldRef Name="City"></FieldRef>  
  8. </ViewFields> 

Right-click on the project and select Deploy:

Deploy

After deploying a List Definition, check this list in web application:

Go to Site Action -> More Options

Options

You can see that your MyTestList template is created in the Installed Items template:

Installed Items template