1
votes

First of all I created a few test columns...
Secondly I created a new content type (derived from Document).

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <ContentType ID="0x0101000F16F9EDC2D547C48480B02B918168DD" Name="MyDocContentType1" Group="Custom Content Types" Description="My Document Content Type 1" Inherits="TRUE" Version="0">
    <FieldRefs>
      <FieldRef ID="{d17ecdc8-991a-4efc-a758-bbb522dd2f62}" DisplayName="My Test Column 1" Required="FALSE" Name="MyTestColumn1" />
      <FieldRef ID="{8e9ef300-b566-4939-8b3c-760e13afb6d5}" DisplayName="My Test Column 2" Required="FALSE" Name="MyTestColumn2" />
    </FieldRefs>
    <DocumentTemplate TargetName="~site/_cts/MyDocContentType1/MyDocumentTemplate1.dotx" />
  </ContentType>
</Elements>

Next I created a module deploying my word 2013 template file (.dotx) to /_cts//MyCustomTemplate1.dotx

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="DocumentTemplates" RootWebOnly="TRUE" Url="_cts/MyDocContentType1">
    <File Path="DocumentTemplates\MyDocumentTemplate1.dotx" Url="MyDocumentTemplate1.dotx" Type="Ghostable" />
  </Module>
</Elements>

Adding the content type to a library enables the document template...
E.g. when I create a new item of "MyDocContentType1" it opens up Word 2013.
However the document template is not correctly bound to the server - the document information panel doesn't appear and I cannot add any quick parts refering to sharepoint content type columns.

It does work when I assign the document template via the SharePoint Web UI.

Any ideas?

Edit: The word template (.dotx) is already aware of the SharePoint columns. In a previous step I assigned the DocumentTemplate manually (to design the word template). Now that the .dotx template is feature complete I want to deploy it as part of a SharePoint solution (for example to a newly created site collection).

Edit: Of course it works using a programmatic approach assigning the DocumentTemplate property via feature event receiver. That's not the solution I am looking for. Declarative only.

To me it looks like a bug. If I go to the content type, edit/update the document template (updating - not uploading a new one!) and create a new document from that content type it starts to work... ?!

1
I have edited your title. Please see, "Should questions include “tags” in their titles?", where the consensus is "no, they should not".John Saunders

1 Answers

1
votes

I am going to assume that you created your *.dotx file directly in word and added it to Visual Studio.

The reason why it doesn't work is that the dotx file needs to have references to the SharePoint fields encoded in the Word file itself.

I would suggest to:

  • Deploy your content type without any document template
  • Add the content type to a document library
  • Edit the newly created list content type (inside the document library) and upload a blank empty *.dotx template: now SharePoint will create a copy of your dotx file, add all the content type columns, and save the new dotx file in the Forms/ folder in your document library ; After this, you have a blank dotx file with the correct associations - test it by adding a new document in your document library with your content type and check the information panel
  • Open the document library in SharePoint Manager (or with SharePoint Designer, or navigate to the Forms/ folder) and download the SharePoint-generated dotx file
  • Customize this dotx file to your needs
  • Delete the document library and retract your wsp package
  • add the final dotx to your solution and your content type just like you did before