December 08, 2008

How to set custom forms (new, edit and display) for a specific content type by CAML definition

Let's imagine a content type e.g. Student and you want to set custom forms for it (new, edit and display). The custom forms have to be declared under the XmlDocuments node of the content type CAML definition.

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType
        ID="0x01004037ADCF3A5C4b648FFC4DA96C965CDE"
        Name="Student"
        Description="Create a new student"
        Version="0"
        Group="Custom Content Types" >
    <FieldRefs>
      <!-- add in and rename built-in WSS Title column-->
      <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" Name="Title" DisplayName="Name" Sealed="TRUE"  />
      <!-- custom fields-->
      <FieldRef ID="{756D3B72-AC72-4e0a-8B6D-1E2573251816}" Name="CardNumber" DisplayName="Card Number" />
      <FieldRef ID="{0D6C76FD-A9B6-4613-9429-06385411E9D7}" Name="StudyYear" DisplayName="Study Year" />
    </FieldRefs>
    <XmlDocuments>
      <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
        <FormUrls xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms/url">
          <New>_layouts/STUDENT/APPLICATIONPAGES/NewStudent.aspx</New>
          <Edit>_layouts/STUDENT/APPLICATIONPAGES/EditStudent.aspx</Edit>
          <Display>_layouts/STUDENT/APPLICATIONPAGES/DisplayStudent.aspx</Display>
        </FormUrls>
      </XmlDocument>
    </XmlDocuments>
  </ContentType>
</Elements>

No comments: