1

I want to create a new document library definition for general use in our SharePoint environment. This new list has some predefined content-types. Users will add this list themselves one or more times to the site they are working in (via Site Actions, Add list).

This is working fine, I've copied the OOTB DocLib definitions, renamed it and added my custom contenttype (defined in an other feature). When I create a list based on this schema/list definition the right contenttypes, and the columns are added to the new list.

The only thing missing are the templates defined for these content-types. The templates are correctly provisioned to the global _cts/myContentTypeA folder. But they are not copied to the local resources folder of the newly created list. The TargetFolders are created, empty though.

When I delete the contenttype and re-add it (all in the UI) the templates ARE copied.

What do I have to write in CAML to make this work?

Schema

<List xmlns:ows="Microsoft SharePoint" 
  Title="My DocLib" 
  EnableContentTypes="TRUE"
  FolderCreation="FALSE"
  VersioningEnabled="FALSE"
  Direction="$Resources:Direction;"
  Url="Documenten"
  BaseType="1"
  xmlns="http://schemas.microsoft.com/sharepoint/">
  <MetaData>
    <ContentTypes>
      <ContentTypeRef ID="0x010100EED05E02DB9F4831932432C1B47334B201">
        <Folder TargetName="Forms/myContentTypeA" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x010100EED05E02DB9F4831932432C1B47334B202">
        <Folder TargetName="Forms/myContentTypeA" />
      </ContentTypeRef>
      <ContentTypeRef ID="0x010100EED05E02DB9F4831932432C1B47334B203">
        <Folder TargetName="Forms/myContentTypeA" />
      </ContentTypeRef>

    </ContentTypes>
    <Fields>
      ...
    </Fields>
    <Views>
      ...
    <Views>
 </List>

ListTemplate elements.xml

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ListTemplate
    Name="mydoclib"
    Type="13001"
    BaseType="1"
    OnQuickLaunch="TRUE"
    SecurityBits="11"
    Sequence="111"
    Category="Libraries"
    DisplayName="My DocLib Documentbibliotheek"
    Image="/_layouts/images/itdl.gif"
    DocumentTemplate="101"
    DisallowContentTypes="False"
    FolderCreation="FALSE">
  </ListTemplate>
</Elements>

ContentType definition

<ContentType ID="0x010100EED05E02DB9F4831932432C1B47334B201"
           Name="myContentTypeA"
           Group="myGroup"
           >
  <DocumentTemplate TargetName="myContentTypeA.dotm"></DocumentTemplate>
  <Folder TargetName="_cts/myContentTypeA"></Folder>
  <FieldRefs>
    <FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" DisplayName="Onderwerp"/>
    <FieldRef ID="{039DC5A3-698A-46cc-AF75-0D0B1A1718CE}" Name="Datum" />
    <FieldRef ID="{7B8E56E4-DD61-4f24-BA0E-9E728A5CC9D2}" Name="Ons Kenmerk"/>
    <FieldRef ID="{BD4903C5-E667-4184-8878-4E14F67533FD}" Name="Uw Kenmerk" />
    <FieldRef ID="{E97E2124-CECC-4666-9B42-10299C35E5D0}" Name="Adres" />
  </FieldRefs>
  <XmlDocuments>
    ...
  </XmlDocuments>
</ContentType>
<Module Name="myContentTypeA" Path="templates"
        Url="_cts/myContentTypeA" RootWebOnly="TRUE">
  <File Url="myContentTypeA.dotm" Type="Ghostable" />
</Module>

Same for others (B and C)

1 Answer 1

1

You also need to duplicate the template inside the folder library itself. Here is a nice artile on how to do it. Also you need to add DocumentTemplate and Folder nodes to the schema.xml in the respective content type.

Update: After reading the comments did a test and this is what worked for me.

<ContentType ID="0x0101004b60f7c3b1ba437f8853236e9bbb3903"
               Name="ListDefWithTemplate1"
               Group="Custom Content Types"
               Description="My Content Type"
               Inherits="TRUE"
               Version="0">
    <FieldRefs>
    </FieldRefs>
    <Folder TargetName="/_cts/ListDefWithTemplate1/" />
    <DocumentTemplate TargetName="Timesheet.xls" />
  </ContentType>

And in my schema, I added

<Folder TargetName="Forms/ListDefWithTemplate1" />
<DocumentTemplate TargetName="Timesheet.xls" />
5
  • I know I have to duplicate the template in the library itself. But how to do that in CAML? I don have a list-instance since the end user must be able to create the list (multiple instances of it) themselves. I'll try with duplicating the whole ct-def in the list-def.
    – Dribbel
    Jun 18, 2012 at 20:11
  • Look at the link in the answer, at the very end (ListInstance element, where he also includes module element). You basically copy the template from _cts/.. to library/CTName/..., when the list instance is created. You can use a module to do it.
    – sssreddy
    Jun 18, 2012 at 20:17
  • Again: I don't have, and can't have listinstances! It should be a template end-users can use. The end-users will create new lists (one or more in a web) based on this template.
    – Dribbel
    Jun 19, 2012 at 7:07
  • Dribbel, look at the updated answer. Hope this works out for you.
    – sssreddy
    Jun 19, 2012 at 19:47
  • Thanks! Now it works. I did have to copy the full field definitions and the full contenttype definitions to the Schema file. Using ContentTypeRef doesn't work. The full CT-def with the Folder and DocumentTemplate elements did the trick. Thanks again!
    – Dribbel
    Jun 21, 2012 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.