Friday 27 April 2012

Provision Content Type via XML


In your solution Explorer add the content type item.


click add, next select the base content type Item to inherit from.


Once selected click finish, and you're ready to start provisioning your content type


to quickly explain some of the properties
  • ID: unique id of the content type, in this case 0x0100 is the Id for item, the following hex number is a GUID
  • Name: this is the a readable name, make it short and sweet
  • Group: helps you organize your content types, again make it descriptive
  • Description: Lets the user know what your content type is for
  • Inherits: lets your content type to include the columns from and inherited ct's.
  • Version: not too sure, i leave it as 0,
This is what I have for my Coffee Content type


So lets go back and create some Site Columns:
  • Id - unique id
  • Title - Out of the box
  • Region - Choice Field
  • Supplier - look up list
  • Start Date - Date with default value of today
  • Price - Price Per Ton
Create Custom Site Columns

With our Custom Site columns made we can load them into our Content type we add them to our content type

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <!-- Parent ContentType: Item (0x01) -->
  <ContentType ID="0x01004640ea11f8fd45f9b930ada1806ab7dd"
               Name="Coffee"
               Group="Custom Coffee"
               Description="Content type for Coffee"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
      <FieldRef ID="{9749FAFE-B58C-4945-85B9-C360C5E309C1}" Name ="CoffeeID" DisplayName="Coffee ID" Required ="TRUE"/>
      <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Coffee Name" Required="TRUE" />
      <FieldRef ID="{FE2F4BE0-6FB3-4EC6-922B-FA3641745EC5}" Name="CoffeeRegion" DisplayName="Region" Required="TRUE"/>
      <FieldRef ID="{A4AC9AEE-3FD3-457F-A8D6-50C0E86363B6}" Name="CoffeeSupplier" DisplayName="Supplier" Required="TRUE"/>
      <FieldRef ID="{4206013B-2B16-441B-A6AD-2E1DAE6C4A86}" Name="CoffeeStartDate" DisplayName="Start Date" Required="TRUE"/>
      <FieldRef ID="{EFE8441B-8A51-427D-ABF4-D9D4ECB1F2E9}" Name="CoffeePrice" DisplayName="Price" Required="TRUE"/>
    </FieldRefs>
  </ContentType>
</Elements>


With our content type set up we can proceed to make a list definition next.