Kwizcom Forms

Create a custom list definition in SharePoint 2010 programmatically

create custom list definition in sharepoint 2010 programmatically

This SharePoint 2010 tutorial explains, how we can create a custom list definition using Visual Studio 2010 for SharePoint 2010.

You can follow below steps to Create custom list definition in SharePoint 2010 programmatically using visual studio 2010.

SharePoint deveopment training course

Create custom list definition in SharePoint 2010 programmatically

First, you create Empty SharePoint Project under SharePoint 2010. See in fig

Create a SharePoint 2010 List Definition
Create a SharePoint 2010 List Definition

Enter the valid SharePoint Site URL and select the checkbox Deploy as a Form Solution and click on Finish. See fig.

create custom list definition in sharepoint 2010 programmatically
create custom list definition in sharepoint 2010 programmatically

Now right click solution and add a new item. Here you select the installed template List Definition. See fig.

Create Custom List Definitions in SharePoint 2010
Create Custom List Definitions in SharePoint 2010
Steps to create List Definition And List Instance In SharePoint
Steps to create List Definition And List Instance In SharePoint

Give the name and Select the type of list. In this dropdown list we able to select Announcements, Calendar, Contacts, Custom List, Document Library, Links, and Tasks. Now I want to create a custom list so I am selecting Custom List. See fig.

Now you able to see your Custom list under solution. Basically, in list folder three file is showing list instance, Element.xml, and Schema.xml. See in fig

Create Custom List definition using Visual Studio 2010
Create Custom List definition using Visual Studio 2010

If you want to change the display name of the list. Then go to under your list definition and click on list instance and open the Element.xml and change the name like see in fig.

Create Custom List definition using Visual Studio 2010 programmatically
Create Custom List definition using Visual Studio 2010 programmatically

Now we add the column Product name and Product Descriptions. Here in SharePoint list by default, the Title Column is created. So we just change the column name Title to the Product name. See in fig and add the following code under element’s tag.

<Field ID=”{3E096E37-09C9-4D23-8753-55EB66CF8BB9}”
Name=”Title”
DisplayName=”Product Name”
Type=”Text”
Required=”TRUE”></Field>
<Field ID=”{3C0B5D7D-194B-4AE4-8A18-6BD1F5DFE9C8}”
Name=”Product_description”
DisplayName=”Product_description”
Type=”Text”
Required=”TRUE”></Field>
Now we add the own content type under the Element.xml
<ContentType
    ID=”0x010089E3E6DB8C9B4B3FBB980447E313CE94″
    Name=”Product Details Item”
    Group=”Custom Content Types”
    Description=”Product Details item content type.”
    Version=”0″>
    <FieldRefs>
      <FieldRef ID=”{3E096E37-09C9-4D23-8753-55EB66CF8BB9}” />
      <FieldRef ID=”{3C0B5D7D-194B-4AE4-8A18-6BD1F5DFE9C8}” />
     </FieldRefs>
  </ContentType>

Whole code looking like this. See in fig

Create Custom List definition using Visual Studio 2010 for SharePoint 2010
Create Custom List definition using Visual Studio 2010 for SharePoint 2010

Now click on schema.xml under your list definition and add the following code.

<ContentTypeRef ID=”0x010089E3E6DB8C9B4B3FBB980447E313CE94″ />
<Field ID=”{3E096E37-09C9-4D23-8753-55EB66CF8BB9}”
Name=”Title”
DisplayName=”Product Name”
Type=”Text”
Required=”TRUE”></Field>
<Field ID=”{3C0B5D7D-194B-4AE4-8A18-6BD1F5DFE9C8}”
Name=”Product_description”
DisplayName=”Product_description”
Type=”Text”
Required=”TRUE”></Field>

Now, schema.xml looks like this –

Steps to create List Definition in sharepoint 2010
Steps to create List Definition in sharepoint 2010

Now we add the column for view purpose under the view tag in schema.xml file. And remember that BaseViewID=1

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

Now, code looks like this –

Create Custom List definition using Visual Studio 2010
Create Custom List definition using Visual Studio 2010

Now Save and deploy your project. Right-click your project and select Deploy.

Create Custom List definition using Visual Studio 2010 for SharePoint 2010
Create Custom List definition using Visual Studio 2010 for SharePoint 2010

See the output in visual studio. Deploy and build is successful.

Create Custom List definition using Visual Studio 2010 programmatically
Create Custom List definition using Visual Studio 2010 programmatically

Now you go to your SharePoint and refresh the page and see the list with your definition’s. See in fig

Create Custom List definition using Visual Studio 2010 for SharePoint 2010
Create Custom List definition using Visual Studio 2010 for SharePoint 2010

You may like following SharePoint 2010 visual studio tutorials:

Hope this SharePoint 2010 tutorial explain, how to create custom list definition in SharePoint 2010 programmatically.

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 Navneet Singh

I am Navneet Singh, Working at C3it software solutions pvt. ltd. in Pune. My core skills are SharePoint 2013, Office 365, SharePoint 2010, SharePoint Designer, SharePoint Designer Workflow, Nintex Workflow, Infopath, Webpart, CSOM/SSOM, Power-shell, C#, ASP.NET and SQL Server.

View all posts by Navneet Singh →