SharePoint 2010 : Create List Definition Using Visual Studio

Introduction

In this article we explore List Definition creation using Visual Studio. Please note that the same can be achieved through the SharePoint Designer as well.

Create List Definition Project

To begin, use the List Definition project in the New Project dialog.

00.png

Enter the name as Coders. Select the site from the wizard as shown below.

1.png

Choose Custom List in the next step.

2.png

Enter the details as shown above and click the Finish button to close the wizard. Now the Solution Explorer looks like below:

3.png

Open the ListDefinition1>ListInstance1>Elements.xml (Please note that there are 2 Elements.xml inside the Solution Explorer)

Change the Title and Url attributes as following:

<?xml version="1.0" encoding="utf-8"?>
<
Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <
ListInstance Title="Coders"
                        
OnQuickLaunch="TRUE" TemplateType="10000"
        
               ="" Url="Lists/Coders"
        
               ="" Description="My List Instance">
  </
ListInstance>
</
Elements>

Now click the Build button and upon success, right-click the project and click Deploy. If no error messages are there, the deployment has succeeded and you will see the new List inside SharePoint.

4.png

On clicking the Coders list you will see the new list opened in SharePoint.

Now we need to add a custom column to the List Definition. Our column is of a single line and named CoderName. The following are the activities included in the Column Creation:

  • Create a new Field
  • Specify the properties like ID (GUID), Name etc.
  • Add the Field Reference inside the Default View

Inside the Fields section of Schema.xml add the following field definition:

<Field Type="Note" Name="CoderName" DisplayName="CoderName" Required="FALSE" ID="{1D54AAC6-DBB8-4454-91B7-E2FAE7697D6A}"></Field>

Inside the ViewFields section of the second View, add the following FieldRef node:

<FieldRef Name="CoderName"></FieldRef>

You can go back to SharePoint and Refresh the Coders List. The changes are visible there:

5.png

The new CoderName property is visible now. This concludes our List creation using Visual Studio. For adding more columns, use the Schema.xml file.

References

http://msdn.microsoft.com/en-us/library/ms466023.aspx
http://onlinecoder.blogspot.com/2011/03/simple-way-of-creating-sharepoint-2010.html

Summary

In this article we have explored the List Definition creation using Visual Studio. The attached source code contains the example we discussed. You can try building and deploying it.