Create SharePoint 2010 List Definition using Visual Studio 2010

Check out Best Alternative to InfoPath


In this article we are going to explain how to create a SharePoint 2010 List Definition using Visual Studio 2010. Open Visual Studio 2010 -> Select File -> New -> Project.
Select the Visual C# -> SharePoint 2010 -> List Definition project template. Enter “MyTestList” in the Name textbox and click on OK.


Read some SharePoint tutorials on:

Create SharePoint 2010 List Definition using Visual Studio 2010
Create SharePoint 2010 List Definition using Visual Studio 2010

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

Create SharePoint 2010 List Definition using Visual Studio 2010
Create SharePoint 2010 List Definition using Visual Studio 2010




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.

Create SharePoint 2010 List Definition using Visual Studio 2010
Create SharePoint 2010 List Definition using Visual Studio 2010

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

Create SharePoint 2010 List Definition using Visual Studio 2010
Create SharePoint 2010 List Definition using Visual Studio 2010

Within the ListInstance element change:
the Title attribute to MyTestList and change the TemplateType attribute to 10009.
<?xml version=”1.0″ encoding=”utf-8″?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>

<ListInstance Title=”MyTestList”

OnQuickLaunch=”TRUE”

TemplateType=”10009″

Url=”Lists/MyTestList-ListInstance1″

Description=” My Test List Instance”>

</ListInstance>

</Elements>

Now, open the Elements.xml file which 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:




<?xml version=”1.0″ encoding=”utf-8″?>

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/”>

<!– 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. –>

<ListTemplate

Name=”ListDefinition1″

Type=”10009″

BaseType=”0″

DisallowContentTypes=”FALSE”

OnQuickLaunch=”TRUE”

SecurityBits=”11″

Sequence=”410″

DisplayName=”MyTestList”

Description=”My Test List Definition”

Image=”/_layouts/images/itgen.png”/>

</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.
<ContentType

ID=”0x010089E3E6DB8C9B4B3FBB980447E313CE94″

Name=”My Test List”

Group=”Custom Content Types”

Description=”My Test List content type.”

Version=”0″>

<FieldRefs>

<FieldRef ID=”{fa564e0f-0c70-4ab9-b863-0177e6ddd247}” />

<FieldRef ID=”{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}” />

<FieldRef ID=”{0248c82f-9136-4b3a-b802-d0b77280b3bc}” />

<FieldRef ID=”{aa4a82dd-5b32-4507-9874-4e1c7bca3279}” />

</FieldRefs>

</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.

<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” />

<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” />

<Field Type=”Text” DisplayName=”Name” Required=”FALSE” MaxLength=”255″ ID=”{0248c82f-9136-4b3a-b802-d0b77280b3bc}”StaticName=”Name” Name=”Name” Group=”Custom Columns” />

<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
<List xmlns:ows=”Microsoft SharePoint” EnableContentTypes=”TRUE” Title=”MyTestList”
FolderCreation=”FALSE” Direction=”$Resources:Direction;”
Url=”Lists/MyTestList-ListDefinition1″ BaseType=”0″
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.
<ContentTypeRef ID=”0x010089E3E6DB8C9B4B3FBB980447E313CE94″ />
<ContentTypes>

<ContentTypeRef ID=”0x010089E3E6DB8C9B4B3FBB980447E313CE94″ />

<ContentTypeRef ID=”0x01″>

<Folder TargetName=”Item” />

</ContentTypeRef>

<ContentTypeRef ID=”0x0120″ />

</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.
<Fields>

<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” />

<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” />

<Field Type=”Text” DisplayName=”Name” Required=”FALSE” MaxLength=”255″ ID=”{0248c82f-9136-4b3a-b802-d0b77280b3bc}”StaticName=”Name” Name=”Name” Group=”Custom Columns” />

<Field Type=”Text” DisplayName=”City” Required=”FALSE” MaxLength=”255″ ID=”{aa4a82dd-5b32-4507-9874-4e1c7bca3279}”StaticName=”City” Name=”Course” Group=”Custom Columns” />

</Fields>

Insert the following XML into the ViewFields element in the 2nd view, BaseViewID=”1″:
<ViewFields>

<FieldRef Name=”Attachments”></FieldRef>

<FieldRef Name=”LinkTitle”></FieldRef>

<FieldRef Name=”Title”></FieldRef>

<FieldRef Name=”ID”></FieldRef>

<FieldRef Name=”Name”></FieldRef>

<FieldRef Name=”City”></FieldRef>

</ViewFields>

Right click on the project and select Deploy:

Create SharePoint 2010 List Definition using Visual Studio 2010
Create SharePoint 2010 List Definition using Visual Studio 2010

After deploying a List Definition, check this list in web application:
Go to Site Action -> More Options…

Create SharePoint 2010 List Definition using Visual Studio 2010
Create SharePoint 2010 List Definition using Visual Studio 2010

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

Create SharePoint 2010 List Definition using Visual Studio 2010
Create SharePoint 2010 List Definition using Visual Studio 2010

You May Also like the Following SharePoint Online Tutorials:

About Sagar Pardeshi

I am Developer working on Microsoft Technologies for the past 6+years. I am very much passionate about programming and my core skills are SharePoint, ASP.NET & C#,Jquery,Javascript,REST. I am running this blog to share my experience & learning with the community I am an MCP, MCTS .NET & Sharepoint 2010, MCPD Sharepoint 2010, and MCSD HTML 5,Sharepoint 2013 Core Solutions. I am currently working on Sharepoint 2010, MOSS 2007, Sharepoint 2013,Sharepoint 2013 App Dev, C#, ASP.NET, and SQL Server 2008.

View all posts by Sagar Pardeshi →