Home > DeveloperSection > Beginner > List Definition in SharePoint 2010

List Definition in SharePoint 2010


SharePoint SharePoint 
Ratings:
0 Comment(s)
 10761  View(s)
Rate this:

List Definition in SharePoint 2010

In this article I am going to explain how to create a SharePoint 2010 List Definition using Visual Studio 2010.

Open Visual Studio 2010 à  Select File à New à Project.

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

Enter "MyList" in the Name textbox and click on OK.

List Definition in SharePoint 2010

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

 

List Definition in SharePoint 2010

Enter "MyList" 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.

List Definition in SharePoint 2010

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

List Definition in SharePoint 2010

Within the ListInstance element change:
      the Title attribute to MyList and change the TemplateType attribute to 10001.

<?xml version="1.0"encoding="utf-8"?>

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">

  <ListInstance Title="MyList"

                OnQuickLaunch="TRUE"

                TemplateType="10001"

                Url="Lists/MyList-ListInstance1"

                Description="My List Instance">

  </ListInstance>

</Elements>

 


Now, open the Elements.xml file which is on the same level as ListDefinition1.
Within the ListTemplate element, change the Type attribute to “10001” and add the DisallowContentTypes=”FALSE” attribute, as shown below:

<?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="10001"

        BaseType="0"

        DisallowContentTypes="FALSE"

        OnQuickLaunch="TRUE"

        SecurityBits="11"

        Sequence="410"

        DisplayName="MyList"

        Description="My List Definition"

        Image="/_layouts/images/itgen.png"/>

</Elements>

 

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

<ContentType

      ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94"

      Name="My List"

      Group="Custom Content Types"

      Description="My List content type."

      Version="0">

      <FieldRefs>

        <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />

        <FieldRef ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" />

        <FieldRef ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}" />

        <FieldRef ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" />

      </FieldRefs>

</ContentType>

 

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

<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" />

 

  <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" />

 

  <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name"Name="Name"Group="Custom Columns" />

 

  <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

<List xmlns:ows="Microsoft SharePoint"EnableContentTypes="TRUE"Title="MyList"
                      
FolderCreation="FALSE"Direction="$Resources:Direction;"
                                
Url="Lists/MyList-ListDefinition1"BaseType="0"
                              
xmlns="http://schemas.microsoft.com/sharepoint/">

 

Insert the following XML into the ContentTypes element in the schema.xml file. This XML describes the MyList Item content type this list will store.

          <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />

 

<ContentTypes>

      <ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />

      <ContentTypeRef ID="0x01">

        <Folder TargetName="Item" />

      </ContentTypeRef>

      <ContentTypeRef ID="0x0120" />

</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.

<Fields>

 

      <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" />

 

      <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" />

 

      <Field Type="Text" DisplayName="Name" Required="FALSE" MaxLength="255" ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"StaticName="Name"Name="Name"Group="Custom Columns" />

 

      <Field Type="Text" DisplayName="Course" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"StaticName="Course"Name="Course"Group="Custom Columns" />

 

    </Fields>

 

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

<ViewFields>

          <FieldRef Name="Attachments"></FieldRef>

          <FieldRef Name="LinkTitle"></FieldRef>

          <FieldRef Name="Title"></FieldRef>

          <FieldRef Name="ID"></FieldRef>

          <FieldRef Name="Name"></FieldRef>

          <FieldRef Name="Course"></FieldRef>

</ViewFields>

 

Right click on the project and select Deploy:

List Definition in SharePoint 2010

After deploying a List Definition, check this list in the SharePoint 2010 Central Administration:

Go to Site Action à More Options…

List Definition in SharePoint 2010

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

List Definition in SharePoint 2010

Thanks for reading this article. I think this will help you a lot.


Don't want to miss updates? Please click the below button!

Follow MindStick