.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Articles >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Create a SharePoint 2010 List Definition

Posted By:Sagar Pardeshi       Posted Date: July 23, 2014    Points: 200    Category: SharePoint    URL: http://www.dotnetspark.com  

In this article we explain how to create a SharePoint 2010 List Definition using Visual Studio 2010
 

In this article we will explain how to create a SharePoint 2010 List Definition using Visual Studio 2010.

Open Visual Studio 2010  then select "File" -> "New" -> "Project...".

Select the Visual C#  -> SharePoint 2010 --> List Definition project template.

Enter "MyTestList" in the Name TextBox and click on OK.

In the SharePoint Configuration Wizard select "Deploy as farm solution" and click on "Next".

Enter "MyTestList" in the What is the display name of the list definition? TextBox.

Select "Custom List" in the What is the type of the list definition? Drop-down box.

In the Solution Explorer, expand ListInstance1 and open the Elements.XML file:

Within the ListInstance element change the Title attribute to MyTestList and change the TemplateType attribute to 10009

01.<?xml version="1.0" encoding="utf-8"?>   
02.<Elements xmlns="http://schemas.microsoft.com/sharepoint/">   
03.  <ListInstance Title="MyTestList"   
04.                OnQuickLaunch="TRUE"   
05.                TemplateType="10009"   
06.                Url="Lists/MyTestList-ListInstance1"   
07.                Description=" My Test List Instance">   
08.  </ListInstance>   
09.</Elements>  

Now, open the Elements.xml file that is on the same level as ListDefinition1.

Within the ListTemplate element, change the Type attribute to "10009" and add the DisallowContentTypes="FALSE" attribute, as shown below:

01.<?xml version="1.0" encoding="utf-8"?>   
02.<Elements xmlns="http://schemas.microsoft.com/sharepoint/">   
03.    <!-- 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. -->   
04.    <ListTemplate   
05.        Name="ListDefinition1"   
06.        Type="10009"   
07.        BaseType="0"   
08.        DisallowContentTypes="FALSE"   
09.        OnQuickLaunch="TRUE"   
10.        SecurityBits="11"   
11.        Sequence="410"   
12.        DisplayName="MyTestList"   
13.        Description="My Test List Definition"   
14.        Image="/_layouts/images/itgen.png"/>   
15.</Elements>  

Insert the following XML into the top of the Elements element in the Elements.xml file. This XML describes the MyTestList Item content type the list will store.

01.<ContentType   
02.      ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94"   
03.      Name="My Test List"   
04.      Group="Custom Content Types"   
05.      Description="My Test List content type."   
06.      Version="0">   
07.      <FieldRefs>   
08.        <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />   
09.        <FieldRef ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" />   
10.        <FieldRef ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}" />   
11.        <FieldRef ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" />   
12.      </FieldRefs>   
13.</ContentType>  

Insert the following XML into the top of the Elements element in the Elements.xml file. This XML describes the Fields the MyTestList Item content type uses.

01.<Field Type="Note" DisplayName="Title" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" StaticName="Title" Name="Title" Group="Custom Columns" />   
02.    
03.  <Field Type="Note" DisplayName="ID" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="ID" Name="ID" Group="Custom Columns" />   
04.    
05.  <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name" Name="Name" Group="Custom Columns" />   
06.    
07.  <Field Type="Text" DisplayName="Course" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="Course" Name="Course" Group="Custom Columns" /> 

In the Solution Explorer, open Schema.xml.

Add the EnableContentTypes="TRUE" attribute to the List element inside of the Schema.xml file.

01.<List xmlns:ows="Microsoft SharePoint" EnableContentTypes="TRUE" Title="MyTestList"    
02.                       FolderCreation="FALSE" Direction="$Resources:Direction;"    
03.                                 Url="Lists/MyTestList-ListDefinition1" BaseType="0"    
04.                               xmlns="http://schemas.microsoft.com/sharepoint/">  
Insert the following XML into the ContentTypes element in the schema.xml file. This XML describes the MyTestList Item content type this list will store

01.<ContentTypes>   
02.      <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />   
03.      <ContentTypeRef ID="0x01">   
04.        <Folder TargetName="Item" />   
05.      </ContentTypeRef>   
06.      <ContentTypeRef ID="0x0120" />   
07.</ContentTypes>  

Insert the following XML into the Fields element. This XML describes the fields the list will store. These are directly related to the fields in the Content Type we added in the previous step.

01.<Fields>    

02.      <Field Type="Note" DisplayName="Title" Required="FALSE" NumLines="6"    
03.RichText="FALSE" Sortable="FALSE" ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" StaticName="Title" Name="Title"Group="Custom Columns" />   
04.    
05.      <Field Type="Note" DisplayName="ID" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="ID" Name="ID" Group="Custom Columns" />   
06.    
07.      <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name" Name="Name" Group="Custom Columns" />   
08.    
09.      <Field Type="Text" DisplayName="City" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="City" Name="Course" Group="Custom Columns" />     

10.</Fields>  

Insert the following XML into the ViewFields element in the 2nd view, BaseViewID="1":

01.<ViewFields>   
02.          <FieldRef Name="Attachments"></FieldRef>   
03.          <FieldRef Name="LinkTitle"></FieldRef>   
04.          <FieldRef Name="Title"></FieldRef>   
05.          <FieldRef Name="ID"></FieldRef>   
06.          <FieldRef Name="Name"></FieldRef>   
07.          <FieldRef Name="City"></FieldRef>   

Right-click on the project and select Deploy:


After deploying a List Definition, check this list in web application:

Go to Site Action -> More Options

You can see that your MyTestList template is created in the Installed Items template:


 Subscribe to Articles

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend