How to include Document Template Files in Content Type Features

I recently spent longer than I should have done trying to create what I thought was a fairly simple feature; one that adds a content type to a site collection and also adds a physical file as the document template. This is a common scenario when developing content types to be used in document libraries. The content type bit was easy, I had done that many times before, but adding the document template did take a while to figure out.

It was with a lot of help from my good friend and SharePoint development guru George Bonney that we managed to get it working so I thought I’d share our findings. George has also blogged about in a couple of related articles here and here.

In order to achieve this, you basically need two features:

· Content Type feature: This will create the content type and any site columns that needs to go with it.

· Modules feature: This will upload the document template and associate it with the content type.

As with most features, both of my features contain a feature.xml file and a manifest.xml file. I won’t go into detail about what these files do, if you are unsure, it might be worth having a look at these MSDN articles Feature.xml Files and Element Manifest (feature).

Creating the Content Type Feature

This is very simple, you can either do this via Visual Studio Extensions for WSS 1.1 and simply go to Add > New Item > Content Type, then fill in the gaps; or you can build the feature from scratch. For clarity, I’ll include steps to build your own.

These steps will basically create a simple Content Type called ‘MyContentType’ which will be in its own group, inherit from the default ‘Document’ content type.

1. Create a folder called MyContentType in C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\FEATURES on your SharePoint server

2. Create a new file called feature.xml

3. Create a Registry Format GUID for your feature; you can do this using GUIDGen.exe or

4. Add the following code to your feature.xml file. Make sure you replace the ‘<Content Type Feature GUID here>’ the actual GUID you generated in step 3 (do not include the curly braces in the GUID).

<?xml version="1.0" encoding="utf-8"?>

Id="<Content Type Feature GUID here>" 
        <ElementManifest Location="Manifest.xml" />

Now we just need to add the content type itself. There are several things to note regarding the ContentType element.

Firstly, the ID specifies the parentage of the content type. There is a whole MSDN article which outlines how Content Type IDs work here. In summary, the ID should be a combination of a new GUID (again, use GUIDGen.exe) and the ID of the parent content type. In this case we want to use the default Document content type as the parent; therefore we need to prefix our new GUID with 0x0101 which is the ID of the document content type.

5. Create a new file called Manifest.xml in the same folder as feature.xml and add the following code in to your Manifest.xml file. Be sure to replace the ContentType ID with ‘0x0101’ plus you own unique GUID, minus the dash symbols.

<ContentType Name="MyContentType" ID="0x0101FE67098470024e0b9272DF90F64061F6" Group="MyContentTypes" Version="0">

<DocumentTemplate TargetName="/_cts/MyContentType/MyDocumentTemplate.dotx" />

You will note that there is a DocumentTemplate element; this is the key line that maps the content type to the actual document template file. The TargetName property points to url of the document template file once it has been uploaded and uses the url of _cts/<name of the content type>/<name of file>. This Url is a hidden part of SharePoint which you can only see in either SharePoint Designer or by opening the site collection via a Network Place. Inside the _cts folder there is a folder that represents each content type in the site collection. These folders are called Resource Folders and are used to store resources for the corresponding content type.

The content type feature is now complete.

Creating the Modules Feature

Now that the content type feature is complete, we can create the modules feature. This feature will actually upload the doucment template to eth right place in SharePoint (_cts/<name of the content type>)

1. Create a folder called MyModule in C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\FEATURES on your SharePoint server

2. Create a new file called feature.xml

3. Create a Registry Format GUID for your feature; you can do this using GUIDGen.exe or

4. Add the following code to your feature.xml file. Make sure you replace the ID for the Feature element with the GUID you generated in step 3. Also replace the FeatureId property in the ActivationDependency element with the Feature ID of the Content Type feature GUID (created in step 3 of the Creating the Content Type Feature section)

<?xml version="1.0" encoding="utf-8"?>



<ElementManifest Location="Manifest.xml" />

<ElementFile Location="MyDocumentTemplate.dotx" />



<ActivationDependency FeatureId="<Content Type Feature GUID here>" />


There are several key things to note with the above code. Firstly you will note that there are two element manifests, the first point points to Manifest.xml which we will discuss in a moment, the second points to the *.docx file that will be the document template (it does not have to be *.docx, it can be any file type).

Secondly, you will notice that there is an activation dependency. This means that this feature (MyModule) will not activate unless the corresponding feature is already activated. In this case, the activation dependency is the MyContentType feature we created earlier. All you need to do is ensure that the FeatureId property is set to the ID of the MyContentType feature (from feature.xml). This is required because unless the content type exists the MyModule feature has nowhere to upload the document to.

5. Create a new file called Manifest.xml in the same folder as feature.xml and add the following code to Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">

<Module Name="MyModule" Url="_cts/MyContentType" RootWebOnly="TRUE">

<File Url="MyDocumentTemplate.dotx" Type="Ghostable" />


The Url property in the Module element points to the Resource Folder that the document template file needs to be uploaded to. The File element includes a Path that points to the actual file that you wish to upload (i.e. its location on the local disk on the SharePoint server).

8. Finally you need to actually add the MyDocumentTemplate.dotx file to the feature folder which will be C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\FEATURES\MyModule (just create any old file for this, so long as it has the same name).

Installing and Activating the Features

In an ideal world these two features would be wrapped up into a SharePoint solution package; however in the interest of clarity, we’ll skip this steps and simply install and activate the features on their own.

1. On the SharePoint server open a command box and navigation to C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\bin

2. Enter and execute the following two commands (one for each feature):

Stsadm.exe –o installfeature –name “MyContentType”
Stsadm.exe –o installfeature –name “MyModule”

3. Now enter and execute the following two commands, replacing http://<your web application name> with the url of your web application:

Stsadm.exe –o activatefeature –name “MyContentType” –url “http://<your web application name>”
Stsadm.exe –o activatefeature –name “MyModule” –url “http://<your web application name>”

Your features are now activated on the site collection, your next step is to associate the content type with a document library and start creating documents.

4. Navigate to the document library you want to use your new content type and go to Settings > Library Settings > Advanced Settings. Enable ‘Allow Management of Content Types’.

5. Now add the content type by clicking ‘Add from existing site content types’ in the Content Types section of Settings > Library Settings for your library.

6. You should now see MyContentType in your libraries’ new menu

This article was published by


Martin Kearn
Senior Consultant
Microsoft Consulting Services UK

Click here for my bio page

Comments (4)

  1. Kyle Bakker says:


    I have created a feature that replaces the out of the box document library with a custom library that contains several content types. The problem is that when a new library is created – everything is there except for the templates for the different content types. I dont want to point the schema.xml directly to the _cts because these are site collections using a managed path. As soon as a content type is updated, it puts the template in place and they work. Is there any way to have the feature populate the forms folder with the templates when the new library is created? I tried using Module, but it needs the listurl when copying to a document library, which does not exist. I could avoid this whole mess if I could just hide the link to create a new document library on the create.aspx page, without also hiding templates created with that feature.

  2. Andrew says:

    Is there a particular reason why you’ve deployed the module and content type as two separate features? Couldn’t the stuff in the Manifest.xml’s be combined (along with addition of ElementFile element in feature.xml)?

  3. says:

    Hi Martin,

    Can I have the sample code for this.

  4. RyanShane says:

    If you were able to deploy your custom template to the Forms folder, how do you specify to the content type where to find that file when the user clicks "New" for the custom content type? I am doing a similar thing it would be useful to know.

    You could probably do something in code with an event handler to deploy it to Forms.

Skip to main content