Pages

Search This Blog

Wednesday, December 14, 2011

Create Custom content type with Custom fields supporting creation of multiple types of documents (.doc, .xls, .ppt) in MOSS

At times, we may have a requirement where in we need to create different type of documents (Word - .doc/.docx , Excel - .xls/.xlsx, Powerpoint - .ppt/.pptx) in a single document library.

So we need to follow the below mentioned steps:

1. Create the required custom fields.

<Field ID="{2B333B0C-05E6-4576-A49E-8713CD6F3FA6}" Name="Field1"      DisplayName="Field1" Type="User" Required="FALSE" Indexed="TRUE"  ShowInNewForm="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE"
Group="Other Columns" >
    <Formula>=Author</Formula>
    <FieldRefs>
      <FieldRef Name="Author"/>
    </FieldRefs>
</Field>

<Field ID="{B8DEEF8E-54AA-4ad9-9AC7-115AC936228E}" Name="Field2"
 DisplayName="Field2" Type="Choice" Required="FALSE" Indexed="TRUE"   ShowInNewForm="TRUE"  ShowInEditForm="TRUE" ShowInDisplayForm="TRUE"
Group="Other Columns" >
    <CHOICES>
      <CHOICE>void</CHOICE>
    </CHOICES>
</Field>
and so on......

2. Create custom content types with the required custom fields.

<!--Generic content type inherited from document content type containing all the fields-->
<ContentType  ID="0x01010D" Name="CustomDocLibWrkspcCT" Group="Document Content Types" Description="Create a document for the document library" Version="0">
  <FieldRefs>
    <FieldRef ID="{2B333B0C-05E6-4576-A49E-8713CD6F3FA6}"  Name="Owner" Required="FALSE" ShowInNewForm="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE"/>
    <FieldRef ID="{B8DEEF8E-54AA-4ad9-9AC7-115AC936228E}" Name="Entity" Required="FALSE"   ShowInNewForm="TRUE" ShowInEditForm="TRUE" ShowInDisplayForm="TRUE"/>
  </FieldRefs>

  <XmlDocuments>
     <XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
        <FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
          <Display>DocumentLibraryForm</Display>
          <Edit>DocumentLibraryForm</Edit>
          <New>DocumentLibraryForm</New>
        </FormTemplates>
      </XmlDocument>
    </XmlDocuments>

</ContentType>

<!--Content types inherited from above created document content type-->
<ContentType  ID="0x01010D0089A4ED8153C04980A6CC1DB53EFA85A9"
       Name="Word Document" Group="Document Content Types"
       Description="Create a word document for the document library"
       Version="0">
    <FieldRefs></FieldRefs>
  </ContentType>

<!--Content type for Excel document-->
<ContentType DocumentTemplate="122"  ID="0x01010D00A09D2732961C4ffe822B33F30117D24F" Name="Excel Document" Group="Document Content Types" Description="Create an excel document for the document library" Version="0">
    <DocumentTemplate TargetName="/_cts/Excel Document/MyTemplate.XLSX" />
    <FieldRefs></FieldRefs>   
</ContentType>

<!--Provision the document template in system content types virtual folder-->
<Module Name="XLSTemplates" Url="_cts/Excel Document" RootWebOnly="TRUE" Path="XLSTemplates" >
    <File Url="MyTemplate.XLSX" Type="Ghostable" />
</Module>

<!--Content type for PowerPoint document-->
<ContentType DocumentTemplate="123" ID="0x01010D0036A1687A93B8415fAE51C38676BACD9F" Name="PowerPoint Document" Group="Document Content Types" Description="Create a powerpoint document for the document library" Version="0" >
<DocumentTemplate TargetName="/_cts/PowerPoint Document/MyPptTemplate.PPTX" />
    <FieldRefs></FieldRefs>  
</ContentType>

<!--Provision the document template in system content types virtual folder-->
<Module Name="PPTTemplates" Url="_cts/PowerPoint Document" RootWebOnly="TRUE" Path="PPTTemplates" >
    <File Url="MyPptTemplate.PPTX" Type="Ghostable" />
</Module>

Note: The templates for these files are uploaded at the location http://minus.com/mtomNJw23

3. Attach these content types to the document library.
In the schema.xml file of the custom document library, within the <ContentTypes> tag, attach the content types created above

<ContentTypes>                 
      <ContentTypeRef ID="0x01010D0089A4ED8153C04980A6CC1DB53EFA85A9">
        <Folder TargetName="Forms/Document"/>
      </ContentTypeRef>
      <ContentTypeRef  ID="0x01010D00A09D2732961C4ffe822B33F30117D24F">
        <Folder TargetName="_cts/Excel Document"/>
      </ContentTypeRef>
      <ContentTypeRef ID="0x01010D0036A1687A93B8415fAE51C38676BACD9F">
        <Folder TargetName="_cts/PowerPoint Document"/>
      </ContentTypeRef>
      <ContentTypeRef ID="0x0120" />
</ContentTypes>

No comments:

Post a Comment