SharePoint 2010 – Create List Definition using Visual Studio

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

Create List Definition Project

For starting use the List Definition project inside New Project dialog.

clip_image002

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

clip_image004

Choose Custom List in the next step.

clip_image006

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

clip_image008

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 on succeed, right click the Project and click Deploy. If no error messages are there, the Deployment succeeded and you can see the new List inside SharePoint.

clip_image010

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

Now we need to add a custom column to the List Definition. Our column is of Single line and name as CoderName. 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 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:

clip_image012

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.

Leave a Reply

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