In case of SharePoint there are several ways to create content types, I guess the most useful to do it is from c# programmatically. There are a lot of blog posts, MSDN descriptions about how to do it, however setting default template from code needs a bit trick.

So, when you’ve created your content type and you also a template document for it, I’m pretty sure that you want to deploy them together in a WSP package. But how to do it? Here it is:

  1. Add a new Module to your SharePoint project and name it like AddIn or something else
  2. Delete the sample.txt from the module
  3. Add your template document to the module, just copy and pate the file into
  4. Modify the Elements.xml in the module like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <Module Name="AddIn" Url="_cts/My Content Type Name">
  <File Path="AddIn/macroenabledXLSXtemplate.xlsm" Type="Ghostable" Url="macroenabledXLSXtemplate.xlsm" />

The module’s url points to the content type and the file element describes the template file. Please note the Path attribute uses ‘/’ istead of ‘\’

  1. Add the reference to the template in the content type definition.

    <DocumentTemplate TargetName="macroenabledXLSXtemplate.xlsm" />

After deploying you should see the template set to the content type.

Last edited Jun 14, 2012 at 11:05 AM by nadasipeter, version 1


No comments yet.