Kwizcom Forms

Create list definition using Visual Studio 2010 in SharePoint 2010

how to create list definition in sharepoint 2010 using visual studio 2010

List definitions are the templates for creating the list and defining a schema for a SharePoint list. It contains information on what views are being used, which columns and content types are being used, and other metadata information. We can create a list definition using visual studio 2010 in SharePoint 2010.

Also, you can read some SharePoint 2013 tutorials:
What are different types of results in MVC?

SharePoint deveopment training course

Impersonation step missing in SharePoint 2013 Workflow

Working with Field Template using JSLink in SharePoint 2013

List definition is used to create multiple list instances from it. Follow below steps to create list definition using Visual Studio 2010.

Step-1:
Open Visual Studio 2010, File -> New Project -> Then in the New Project dialog box choose List Definition project from the list of templates. Then give a name and click on Ok.

Step-2:
In the next dialog box give a local site for debugging and then choose to Deploy as a farm solution and then click on Next.

Step-3:
Then in the SharePoint Customization Wizard, Give a display name for the list definition and chose what is the type of list definition. Here I chose custon list and click on Finish as shown in the figure below:

create list definition in sharepoint 2013 programmatically
create list definition in sharepoint 2013 programmatically

Step-4:
Noe check out the XML files.

1- Elements.xml:
This .xml file only gives general information about the list definition like: Name, Description, Quick Launch etc like bwlow:

<?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=”10000″
BaseType=”0″
OnQuickLaunch=”TRUE”
SecurityBits=”11″
Sequence=”410″
DisplayName=”MyNewListDefinition – CustomListDefinition”
Description=”My List Definition”
Image=”/_layouts/images/itgen.png”/>
</Elements>

2- Schema.xml:
This file defines all the fields. You can add fileds inside <Fields><Field></Field></Fields> tag. Example below

<Fields>
<Field ID=”{DA1D6D10-3047-4A5B-91ED-93A5864153FE}” Name=”FirstName” DisplayName=”First Name” Type=”Text” Required=”TRUE”/>
<Field ID=”{0F97F5C5-BF6A-40F0-A651-3E2B0CE9C520}” Name=”LastName” DisplayName=”Last Name” Type=”Text” Required=”TRUE”/>
<Field ID=”{B53C4419-BA73-45D3-AE3B-F96E8B575052}” Name=”Gender” DisplayName=”Gender” Type=”Choice” Required=”TRUE”>
<CHOICES>
<CHOICE>Female</CHOICE>
<CHOICE>Male</CHOICE>
<CHOICE>Not Specified</CHOICE>
</CHOICES>
</Field>
</Fields>

Here we have added 3 fields name as: FirstName, LastName & Gender.

The full code will be like below:

how to create list definition in sharepoint 2013 using visual studio 2013
how to create list definition in sharepoint 2013 using visual studio 2013

Step-5:
Now we have to give the FieldRef else the fields will not be show in the list. Do like below:

In the same schema.xml file go to the <Views> section (where BaseViewID= “1”) and add fields ref in the <ViewFields></ViwFields> section like below:
<ViewFields>
<FieldRef Name=”Attachments”></FieldRef>
<FieldRef Name=”LinkTitle”></FieldRef>
<FieldRef Name=”FirstName”></FieldRef>
<FieldRef Name=”LastName”></FieldRef>
<FieldRef Name=”Gender”></FieldRef>
</ViewFields>
Here the Name is the name that we have given while defining Fields. It should looks like below:

how to create list definition in sharepoint 2010 using visual studio 2010
how to create list definition in sharepoint 2010 using visual studio 2010

If you want to hide attachment and Title column then you can remove those columns from the <ViewFields> section.

Step-6:
Now Build and Deploy the solution. And then Create a New list. In the available templeates you can chose the list definition that you made now. Then you can create the list.

list definition in sharepoint 2013
list definition in sharepoint 2013

Once you create the list. The list will appear like below:

create list definition sharepoint 2010 using visual studio 2012
create list definition sharepoint 2010 using visual studio 2012

 

Check out Best Alternative to InfoPath -> Try Now

free sharepoint training

SharePoint Online FREE Training

JOIN a FREE SharePoint Video Course (3 Part Video Series)

envelope
envelope

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →