Thursday, April 7, 2011

How to create a custom list definition using visual studio 2010?

In this article we will discuss how to create a custom list definition using visual studio 2010? Here we will create a content type and they we will associate the content type to while creating the list.
Step-1:
First we need to create an Empty SharePoint project.
Open Visual Studio 2010 ->File ->New ->Project->Choose C#.Net in project type and choose Empty SharePoint Project template. -> Then give a project name (CountryList).
In the SharePoint Customization Wizard Choose Deploy as Sandboxed solution -> Finish

Step-2: 
First we need to add a Field definition.
Right click on the Project CountryList ->Add new item -> Choose Empty element -> Give name (CountryField) ->Click Add.

Step-3:
Create one GUID
Go to Tools -> Create GUID -> copy the GUID

Step-4: 
Open the Elements.xml file modify the following changes


<field ID="C6453C8C-8394-4CB3-8AAC-ECE671C6A0C2" Type="Choice" Name="Country" DisplayName="Country Name" ShowInDisplayForm="TRUE" ShowInNewForm="TRUE" ShowInEditForm="TRUE">
<choices>
<choice>India</CHOICE>
<choice>Pakistan</CHOICE>
<choice>Srilanka</CHOICE>
<choice>Bangladesh</CHOICE>
</CHOICES>
</Field>

Step-5: 
Create content type
Select the project CountryList -> Add new item -> Select Content type -> Give name to the content type (CountryContentType) then click Add.
From the Choose content type settings Choose item as base content type.
In the Elements.xml file Add
<fieldref ID="GUID created above" Name="Country" />

Step-6:
Create List Defination.
Select the project CountryList ->Add new item ->select template List Defination From ContentType ->Give A Name (CountryListDefination) and Click on Add.
In the Choose list definition settings select the content type (CountryContentType) we have made in the above step. Check the Add a list instance for this list definition Check box and then click finish.
Step-7:
Now press f5 to deploy the solution.
Then in the browser you will be able to see the List definition.

No comments:

Post a Comment