Provision a Content Type with a Document Template using a Feature – Part 2

In this post we’ll provision a content type with a document template using a feature.

To create the feature we’ll use Visual Studio and WSPBuilder, and we’re going to create 2 content types;

  • 1 which provisions the document template into the _cts/{content type name} folder
  • 1 which provisions the document template into the _layouts folder.

Before we start my project structure looks like this;

Project Structure

Create a standard site collection  scoped feature;

<?xml version="1.0" encoding="utf-8"?>
<Feature  Id="a4c8c426-6d87-4b2f-b109-e7f00b7d6c15"
          Title="My Test ContentTypes"
          Description="Description for MyTestContentTypes"
		<ElementManifest Location="contenttypes.xml"/>
		<ElementFile Location="templates\doc1.dotx"/>

Now create the contenttypes.xml manifest file;

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="">
	<ContentType ID="0x0101002880177DFDC248c38C745E1D664A5FC5"
					 Name="Doc Sample"
					 Description="Test CT with DT"
		<FieldRefs />
		<DocumentTemplate TargetName="doc1.dotx"/>
	<Module Name="PopulateDocTemplates"
			  Url="_cts/Doc Sample"
		<File Url="doc1.dotx" />
	<ContentType ID="0x0101009889C18B0DFB4fc58C8D35C9AB4EDE03"
					 Name="Function Sample"
					 Description="Test CT 2 with DT"
		<FieldRefs />
		<DocumentTemplate TargetName="/_layouts/1033/LCFT/templates/doc2.dotx"/>

* If your content type does not include any additional fields above those of the inherited content type, you must still include the empty <FieldRefs /> element.

The 1st content type (Doc Sample) provisions the document template into the _cts/Doc Sample folder using a Module.

The 2nd content type (Function Sample) provisions the document template into the file system in the _layouts/1033/LCFT/templates folder as a template file.

Build and package up the WSP, deploy and activate the feature.

Published by

Phil Harding

SharePoint Consultant, Developer, Father, Husband and Climber.

3 thoughts on “Provision a Content Type with a Document Template using a Feature – Part 2

  1. Thanks for this Phil. I have been banging my head against the wall until I saw that you need to include an empty FieldRefs element as you highlighted above.

    One thing that I’m stuck on now is that if these content types are added to libraries with custom metadata columns the new content types do not automatically have these columns associated with them.

    Is there a way to do this as the users are not going to want to add the columns to each content type for every library?

    Hope there is an easy solution to this.

  2. I did exactly the same thing. Provision a contenttype with the layout location gave me the a dialog window, asking me to choose the contenttype.
    When I provioned the CT with the _cts location, the Office client loads using the correct template but doesn’t save the document back to SharePoint using the content type you selected, instead using the default content type of the document library.

    So i did not solve the Amnesia Problem: Multiple Content Types on Libraries

    Do you have any ideas about this.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.