How to Create a Custom List Definition for SharePoint 2010 in Visual Studio?

So you have got a custom list created and wanted to make it as a List definition, so that anyone can create instances of the list which has lot of customized columns.

Well, Creating a List definition is relatively simpler in SharePoint 2010. Follow these steps to create a custom list definition in SharePoint 2010 using Visual Studio.

1. Create a New Visual studio Project, choose List definition as the Project type.

2. Update the  <Fields> node in Schema.xml:
SharePoint 2010 custom list definition schema.xml
If you are creating list definition based on content type, You can update the <ContentTypes> node in Schema.xml with the content type reference, fields, etc. Otherwise, Take off the <ContentTypes> node and insert the <Fields> node alone (Here, that’s what we are going to do).

sharepoint 2010 custom list definition schema.xml

How to get the fields schema XML?
We can get the Field Schema XML from Visual Studio 2010 Server Explorer or Using SharePoint Manager 2010.

create list definition sharepoint

Copy the Field Type schema XML and paste them under <Fields> node

<Field Type="Text" DisplayName="Trainer Name" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" ID="{8a9ad061-1de6-4712-bc8d-99af27e2f60d}" SourceID="{7a9e7fc5-edc2-4072-bafd-8770aa819d39}" StaticName="TrainerName" Name="TrainerName" ColName="nvarchar3" RowOrdinal="0" />
<Field Type="DateTime" DisplayName="Training Date" Required="TRUE" EnforceUniqueValues="FALSE" Indexed="FALSE" Format="DateOnly" ID="{38407f75-57b1-4992-bd22-7cae650359d4}" SourceID="{7a9e7fc5-edc2-4072-bafd-8770aa819d39}" StaticName="TrainingDate" Name="TrainingDate" ColName="datetime1" RowOrdinal="0" />
<Field ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Type="Text" Name="Title" DisplayName="Training Title" Required="TRUE" SourceID="https://schemas.microsoft.com/sharepoint/v3" StaticName="Title" FromBaseType="TRUE" MaxLength="255" Indexed="FALSE" ColName="nvarchar4" />

Add Fields to the Default view:
In Schema.xml file navigate to  <Views> <View BaseViewID=”1″… ><ViewFields> node and add the fields to the view. Copy the Name attributes of the <Field> elements (such as Name=”TrainerName”) and place them under ViewFields

SharePoint 2010 list definition add field

<ViewFields>
          <FieldRef Name="Title"></FieldRef>
          <FieldRef Name="TrainerName"></FieldRef>
          <FieldRef Name="TrainingDate"></FieldRef>
</ViewFields>

4. Creating Instances Of Custom List Definition:
You can create List instances of custom list definition by specifying TemplateType and FeatureId parameters in ListInstance’s Elements.xml as Same as the Custom List definition Feature’s. (Just the TemplateType Parameter would do!, FeatureId is optional)

List Instance’s TemplateType and List Template’s Type must be the Same to create a List Instance of the particular List definition.

SharePoint 2010 list Instance element.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="https://schemas.microsoft.com/sharepoint/">
  <ListInstance Title="Training List"
                OnQuickLaunch="TRUE"
                TemplateType="10001"
                Url="Lists/TrainingList"
                Description="Training List for Portal">
  </ListInstance>
</Elements>

sharepoint 2010 list definition example
Build & Deploy the solution. That’s all! We are done creating SharePoint 2010 custom list definition using Visual Studio.

Last but not Least:

  • It is possible to create a List definition from a Content type. Visual studio offers project template for creating list instance from content type. All you have to do is: Create a Content Type Project, Add relevant fields to the Content type. Once done, Add New Item >> choose “List Definition From Content Type”. 

MSDN Post on create list definition SharePoint 2010 existing list: https://msdn.microsoft.com/en-us/library/gg276355.aspx

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

Your email address will not be published. Required fields are marked *