Programming Lists using CAML in SharePoint 2010. Create Content Type.
This article describes how to programming lists using CAML in SharePoint 2010. Examples were also taken from PluralSight site.
Creating Content Types using CAML:
1. Create new SharePoint project and add new Empty Element.
2. Call the element as SiteColumns and field elements. Code can be taken from a server explorer if a SharePoint site already has a prototype of the list. Field ID values should be changed (Generate GUID tool can be used)
3. Add new Content Type item and select Item as a based content type.
4. Open the Elements.xml and change the following properties:
- Name
- Group
- Description
- Inherits should be false to redefine fields
5. Inside FieldRefs section, add new fields references. ID should be the same as in the SiteColumns file except for “Title” where ID is taken from base content type.
SiteColumns file:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field DisplayName="Bio"
Type="Note"
Required="FALSE"
ID="{4BF9541B-D24B-40E8-BEDA-45F747649C22}"
StaticName="Bio"
Name="Bio"
Group="PluralSight"
NumLines="6"
RichText="FALSE"
Version="1" />
<Field DisplayName="Employee"
Type="Boolean"
Required="TRUE"
ID="{C90086CA-5382-444C-9269-434E48FC132D}"
StaticName="Employee"
Name="Employee"
Group="PluralSight"
Version="1" />
<Field DisplayName="Salary/Rate"
Type="Currency"
Required="FALSE"
ID="{2CEF6FDE-B198-4761-9D0B-2880E928FB96}"
StaticName="SalaryRate"
Name="SalaryRate"
Group="PluralSight"
Version="1" />
</Elements>
Content Type:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="0x0100FA10CAABDE214D22AC081096EA118DDA"
Name="Author"
Group="PluralSight"
Description="Author Content Type"
Inherits="FALSE"
Version="0">
<FieldRefs>
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Name" Required="TRUE"/>
<FieldRef ID="{C90086CA-5382-444C-9269-434E48FC132D}" Name="Employee" Required="FALSE"/>
<FieldRef ID="{2CEF6FDE-B198-4761-9D0B-2880E928FB96}" Name="SalaryRate" Required="TRUE"/>
<FieldRef ID="{4BF9541B-D24B-40E8-BEDA-45F747649C22}" Name="Bio" Required="FALSE"/>
</FieldRefs>
</ContentType>
</Elements>
Other CAML actions will be described in the next articles.
Programming Lists using CAML in SharePoint 2010. Create List.
Programming Lists using CAML in SharePoint 2010. Create List based on a Content Type.
