How to deploy custom content type with word document template using visual studio?

已答复 How to deploy custom content type with word document template using visual studio?

  • Wednesday, April 11, 2012 7:46 PM
     
     
    I created content type for document library using visual studio. Currently I have manually added word document template to the document library content type which contains quick part properties from my content type. Now I want to do it programmatically. I mean, i want to add word document template to my project and add that word template to content type and deploy it as feature. Anyone has idea? Please try to explian step by step. Thanks.

    AshitaP


    • Edited by AshitaP Thursday, April 12, 2012 5:27 PM
    •  

All Replies

  • Wednesday, April 11, 2012 9:10 PM
     
     Answered

    Hi Ashita.

    Doing this using Visual Studio is pretty easy, this guide will show you the exact steps:

    Deploying documents with content types and associating content types with libraries (Part I)http://blogs.msdn.com/b/vssharepointtoolsblog/archive/2010/05/26/deploying-documents-with-content-types-and-associating-content-types-with-libraries-part-i.aspx

    If youre in a sandboxed environment, then you will need to deploy the document file to a different place, but in a farm mode scenario this will work.

    Good luck

    Regards


    Thomas Balkeståhl - Technical Specialist - SharePoint - http://blog.blksthl.com
    Download the SharePoint Branding Project here

    • Marked As Answer by AshitaP Thursday, April 12, 2012 12:52 PM
    •  
  • Monday, April 16, 2012 4:01 PM
     
     Answered Has Code

    I appriciate the help provided by Thomas. The idea is working to deploy word doc template in Layout folder. But I wanted to deploy it into _cts folder with content type.

    Finally, I found the soltion for that.

    Step 1: In your content type code, add following code after <FieldRefs></FieldRefs>.

    <Folder TargetName="_cts/YourFeatureName/YourContentTypeName" />
        <DocumentTemplate TargetName="YourTemnplate.docx" />
      </ContentType>
      <Module Name="YourContentTypeName" Url="_cts/YourContentTypeName" RootWebOnly="TRUE" Path="YourContentTypeName" >
        <File Url="YourTemplate.docx" Type="Ghostable" />
      </Module>

    Right click on your content type in solution explorer, click add existing file and then browse to your word document template and add it to content type.

    Add your Documet Template File(.docx) to 'C:/Program Files/Common Files/Microsoft Shared/Web Server Extensions/14/Template/Features/YourFeatureName/YourContentTypeName'.

    Now deploy it and you are all set.


    AshitaP

    • Marked As Answer by AshitaP Monday, April 16, 2012 4:01 PM
    •  
  • Thursday, August 23, 2012 9:48 PM
     
      Has Code

    I have successfully got my Content Type to include a custom Document Template. However, when I try to include the Content Type with a custom List Definition the Document Template is not included with the List. Any ideas?

    Element.xml

    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <!-- Parent ContentType: Document (0x0101) -->
      <ContentType ID="0x01010062188da313be476c8426c7595ced7355"
                   Name="$Resources:HomeownershipDocument"
                   Group="$Resources:ContentTypes"
                   Inherits="TRUE"
                   Description="$Resources:HomeownershipDocument_Description;"
                   Hidden="FALSE"
                   Version="0">
        <FieldRefs>
        </FieldRefs>
        <Folder TargetName="_cts/Homeownership Document" />
        <DocumentTemplate TargetName="template.dotx" />
      </ContentType>
      <Module Name="Templates" Path="Homeownership Document" Url="_cts/Homeownership Document">
        <File Url="template.dotx" Type="Ghostable" />
      </Module>
    </Elements>

    Schema.xml

    <MetaData>
        <ContentTypes>
          <ContentType ID="0x01010062188da313be476c8426c7595ced7355" Name="HomeownershipDocument">
            <DocumentTemplate TargetName="template.dotx" />
            <Folder TargetName="Forms/Homeownership Document"/>
            <FieldRefs>
            </FieldRefs>
          </ContentType>
        </ContentTypes>
        <Fields>...</Fields> <!-- removed for brevity -->
        <Views>...</Views> <!-- removed for brevity -->
        <Forms>...</Forms> <!-- removed for brevity -->
    </MetaData>



    Anthony Conrad