Create Content Types Programatically in SharePoint.

Leave a Comment
The Following example will demonstrate how we can create the Site Content Type Programmatically using the Declarative XML.
<!-- Parent Content Type Item:(0x01) -->
<ContentType ID="0x0100da3896467d2d4af085f58a0fa1c22703" Inherits ="TRUE"   Group ="MyCTGrp"    Name ="CT1" Overwrite ="TRUE" Description ="This content type is used for the....">
    <FieldRefs >
      <FieldRef ID ="{860deaeb-80cd-4a22-ab0d-31e49b67ac90}"  Name ="SiteCol1" DisplayName ="SiteCol1" Required ="TRUE" />
      <FieldRef ID ="{b287cd46-13b5-4a56-8a18-c0247804aa96}"  Name ="SiteCol2" DisplayName ="SiteCol2"  Required ="TRUE" />
      <FieldRef ID ="{5e86344f-8a18-4e72-9117-bcee35b72430}"  Name ="SiteCol3" DisplayName ="SiteCol3" Required ="FALSE" />
    </FieldRefs>
  </ContentType>

<!-- Parent Content Type Video:(0x0101009.....) -->
<ContentType ID="0x0101009148F5A04DDD49CBA7127AADA5FB792B00291D173ECE694D56B19D111489C4369D0002944d4fe73b47c4b4fc617611fa4d52"  Inherits ="TRUE"  Group ="MyCTGrp"    Name ="CT2"   Overwrite ="TRUE"    Description ="This content type is used for the video">
    <FieldRefs >
      <FieldRef ID ="{de2f4df0-b742-40ee-86d7-2fcd05ecbd8e}"
         Name ="SiteCol4"
         DisplayName ="SiteCol4"
             Required="FALSE" />
    </FieldRefs>
  </ContentType>
If you want to create a content type and want to make a document as a Parent.
for that we have to give like Parent Content Type ID+00+GUID
If we want to inherit one content type from another content type follow the above procedure.

Reference:http://msdn.microsoft.com/en-us/library/aa543822.aspx

Related Post

0 comments:

Post a Comment