Search This Blog

Tuesday, March 17, 2015

Developing a List Definition in SharePoint 2010


This tutorial will guide you through creating a SharePoint 2010 List Definition using Visual Studio 2010.

Open Visual Studio 2010

From the Visual Studio 2010 menu, select File --> New --> Project....
Select the Visual C# --> SharePoint 2010 --> List Definition project template.
Enter "Music" in the Name textbox and click on OK.

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




















Enter "Music" 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 (do not confuse this Elements.xml file with the other Elements.xml file which is on the same level as ListDefinition1)


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


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 theDisallowContentTypes=”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"
DisallowContentTypes="FALSE"
Type="10001"
BaseType="0"
OnQuickLaunch="TRUE"
SecurityBits="11"
Sequence="410"
DisplayName="Music"
Description="My List Definition"
Image="/_layouts/images/itgen.gif"/>
</Elements>

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

ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94"
Name="Music Item"
Group="Custom Content Types"
Description="Music item 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 Music Item content type uses. 
<Field Type="Note" DisplayName="Description" Required="FALSE" NumLines="6" RichText="FALSE" Sortable="FALSE" ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="Album Description" Name="Album Description" Group="Custom Columns" />The Elements.xml file should now look like the following.


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


<Field Type="Text" DisplayName="Artist" Required="FALSE" MaxLength="255" ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}" StaticName="Artist" Name="Artist" 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












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

<ContentTypeRef ID="0x010089E3E6DB8C9B4B3FBB980447E313CE94" />



















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. 

<Field Type="Note" DisplayName="Description" Required="FALSE" NumLines="6" RichText="FALSE"

Sortable="FALSE"
ID="{cb55bba1-81a9-47b6-8e6c-6a7da1d25602}" StaticName="Album Description"
Name="Album Description" Group="Custom Columns" />
<Field Type="Text" DisplayName="Title" Required="FALSE" MaxLength="255"
ID="{0248c82f-9136-4b3a-b802-d0b77280b3bc}"
StaticName="AlbumTitle" Name="AlbumTitle" Group="Custom Columns" />
<Field Type="Text" DisplayName="Artist" Required="FALSE" MaxLength="255"
ID="{aa4a82dd-5b32-4507-9874-4e1c7bca3279}"
StaticName="Artist" Name="Artist" Group="Custom Columns" /> 

Insert the following XML into the ViewFields element in the 2nd view, BaseViewID="1". This XML describes which fields should be visible in this particular view. BaseView 1 is set as the default view and this is the view the newly created fields should display in.

<ViewFields>

<FieldRef Name="Attachments"></FieldRef>
<FieldRef Name="LinkTitle"></FieldRef>
<FieldRef Name="Album Description"></FieldRef>
<FieldRef Name="AlbumTitle"></FieldRef>
<FieldRef Name="Artist"></FieldRef>
</ViewFields> 
  
 From the menu, select Build 
From the menu, select Deploy
Open your target SP2010 website in a browser session. 
Under Lists in the left-side navigation, click on Music to view the new list.





No comments:

Post a Comment