Leveraging Templates to Create Documents in SharePoint Library

Blog written by: 
Chris Ang
SharePoint Architect
CCNA, MCPD, MCTS, A+

SharePoint Document Templates and Content Types

Intro

Organizations seldom take advantage of using document templates to create or add a new document in SharePoint Document Library, although this feature has been available since SP2007.

There are several advantages of creating a SharePoint document automatically via a template, especially when a preferred outline needs to be used for say, creating a marketing campaign or a business proposal. While a template ensures consistency, users also can save time on building the format of the document as prescribed by the organization.

Let’s say you want to create a new sales quote with the existing template you have in Word format. What you would do out of habit is, open the Word template, make changes as per your new quotation and then save that new file in SP document library. However, SharePoint has features that will save your time and get the exact same result in a more efficient manner. SharePoint has a functionality that allows you to create a new document directly from the document library based on the defined template for that library. You can define a template by making changes to the default template and using that pre-formatted template to create new versions of your sales quotes.

Templates are useful when creating forms too. For example, an expense form or a training request form in MS Word can simply be added by a user based on a previously uploaded file in the Document Library and by clicking “Add New Expense Form”.

There are three ways in which users can leverage the concept of templates in SharePoint. (i) by using a library template, (ii) by using a content type template and (iii) using a library to manage the Document templates.

While the library template is very easy to use, it limits the users in the sense that all the documents contained in the particular library need to necessarily use the defined metadata in that library. So, the usage of the library template is restricted and can’t be used anywhere else in the site or site collection. To overcome this problem, SharePoint 2007 brought in the concept of ‘Content Types’, which simply put is a collection of metadata fields that may be applied to the document.

Let’s talk about the various steps involved in creating a new content type in user-interface and then adding it to a document library.

Step 1: Create the Content Type

Content types are basically created at the site / site collection level; hence, they are available within the site as well as the sites below them. If created at the root of the site collection, the content type would be available to the entire site collection.

In order to do this, go to the root site, select “Site Actions” -> Site Settings
Now, got to the Content Type Gallery, where all the content types are stored. And select “Site Content Types”.

Let’s say you want to create a template for Letter – type in “Letter” in the content type and click the “Create” button. Now, this “Letter” with all the inherited properties like Name, Title etc. from the “Document” content type is ready to be termed as a group by selecting the “My Custom Types” group. Upon creating the “Letter” content type, you can add all required custom fields to this content type.

Using SharePoint Document Templates

Step 2: Add Metadata to the Content Type

Metadata is a fancy word for a ‘column’ or ‘field’, such as a person’s name or age. A ‘Content Type’ will store a collection of these fields/metadata. Essentially, we use metadata to capture extra information about a document that helps with search and describes information about the document. Adding metadata involves creating columns in the Content Type Information Page. If a column name is already in use, then you need to create a new name. It’s advisable to put all new columns in one group for easier updating when required.

Once the new Content Type “Expense Report” is created, click ‘Add from new site column’ to add metadata/fields that relate to this ‘Expense Report’. For example, you may want to capture ‘Expense Date’ or ‘Expense Amount’. NOTE: You could also use existing columns (if you created ones before) or use ones that are present by default from SharePoint.

SharePoint Content Type Columns

I click “Add from new site column” and the window below appears. Here I can add my new columns/metadata:SharePoint Custom Content Type new Field

I added 3 below for this example:

Step 3: Creating and Uploading Word File

This is required because in Content Types, the document template is not automatically created when the content type is created. This also allows us to upload a ‘Company Branded’ file, which we may already have handy.

Here, we click “Advanced” to attach the actual MS Word document to use for this ‘Expense Report’

 

 

 

 

 

To make it simple, I will start with a very simple MS Word file and then edit it after. So, go to Word and create a new document. Save the document and make a note of its location.

Save the MS Word document as DOCX or DOTX (I found both work fine in my testing so far).

Browse and upload this MS Word Document. Then click OK.

Step 4: Create a Library for Template Customization

While the document template created in the previous step allows for editing, you cannot directly change anything in the metadata fields because it seems MS Word only recognizes the fields from the library (that contains the document).

I am not sure why exactly this was designed like this or if it is a bug or an error on my part, but I have always had to add/map the fields/metadata to MS Word from within the Document Library (vs. from the actual Content Type itself (above)), and then use that updated document as the ‘template’ to replace the template in the Content Type. Hope that makes sense..)

Hence a document library needs to be created, which will use the newly created content type. Thereafter, we will modify the template, map the new metadata/fields, and then the content type template needs to be replaced with this ‘updated’ document.

So, first you need to add a new document library to the site, I just used the default “Documents” library for my example here.

Second, go to the new library then select Library Tab -> Library Settings – > Advanced Settings. Here, choose the Yes option in “Allow management of content types”.

You should see this screen below, select Yes as I highlighted below:

Then Click “Add from existing content types”, you should then see the “Add Content Type” screen, I changed to only show my Acme Corp – Content Types, the screen below:

Add your content type by selecting it and clicking Add. Then Click OK.
We should now see the new Expense Report Content Type in our Library.

I clicked “Change new button order and default content type” to remove the default “Document” content type option, so that users will only be allowed to create “Expense Reports” in this library.

Step 5: Create a new Document in the Library

Once you have removed the default Document, you need to create a new document that will be associated with the content type in the library.

IMPORTANT:
This is where the real magic happens and you can MAP metadata to inside fields in the MS Word file. We will overwrite the template with this new file. Then later, I will show you how you can update multiple MS Word files at once by updating the SharePoint Column  values in Quick Edit/Datasheet view!

In the Document Library, click Files (or “Documents” in older versions of SharePoint) -> New Document and choose “Expense Report” (or whatever you called your Content Type)

This will open a new Document, called “Document1.docx”.

It will have the same content as the Content Type template we used. From here, however, we will map the fields.

 

We should now be able to Click Insert->Quick Parts and view the metadata/fields that we added earlier.

Save this document, note the location as we need to upload it shortly.

IMPORTANT NOTES:
Be sure to keep a backup copy of your template file. Also, be cautious about updates to this template file and that it will not automatically update existing files in your Document Libraries.

 

 

 

Step 6: Replace the Existing Content Type Template

Now that the formatted “Expense Report” template is created, you need to replace the originally created content type template (which did not have the field mapping) with this new one.

So, go back to Site Content Gallery -> Site Settings -> Site Content Types. Select “Expense Report” template.
Now, click on Advanced Settings and replace the existing template with the new one by uploading it from your file system.

Click OK, then go back to “Advanced Settings” and you can now click “Edit Template”

This completes your creation of new content type and using it as template for your documents. Users can create a new library to test it, change the metadata values in the document and save it to see the effectiveness of the overall process.

Step 7: Bulk Updating Content in multiple MS Word documents by using mapped SharePoint metadata

If we have multiple “Expense Reports” for example, I could use datasheet view, also called “Quick Edit”

I’ll open up one of these files that I want to update, let’s say “Expense Report – Copy (2)”

Now, I’ll go back to my Library, and click “Library->Quick Edit”

I’ve quickly added some arbitrary data here:

Notice the values highlighted. That was a quick edit!

Now, if I open up the document, the values inside the file(s) are automatically set! Wow that’s pretty cool!

Again, be cautious of updates and make sure you have backups. I have experienced sometimes files can get corrupted when they get complex, MS Word essentially is made up of xml data it seems which if there are errors, it does not like it..

Another ‘shorter’ way to do this all, is to skip the use of the Content Type and just modify the Document Library template used.

Creating a new content type and adding it to library gives users the flexibility to change content types at the root level, so you can use the content type in multiple libraries and just update it once from the root site ‘Content Types’ gallery section.

Hope you found this useful!

References:
https://support.office.com/en-us/article/Set-a-file-template-for-a-document-or-form-library-45da4fcb-1fe8-4c7e-b41f-d5b824dd28f8

Do you use SharePoint? Try our toolkit
Download SharePoint Essentials Toolkit Now
Download the SharePoint Essentials Toolkit
Chris Ang

6 thoughts on “Leveraging Templates to Create Documents in SharePoint Library

  1. Excellent read, I merely passed this onto a colleague who was doing little research on that. And the man actually bought me lunch because I found it for him smile So let me rephrase that: Thank you for lunch!

  2. Really good post. I’ve done it like you wrote and it works fine, but i’ve a problem with the versioning.
    I have a word template in an extra document library. Now i create subsites with document libraries use this doc library with the templates. Each template has a table on the first site with informations about “Author”, “Creation Date” and “Version”.
    Problem: when a user creates a new document in his doc library the version shown is the version of the template doc. How can i solve this Problem? (my version field is ab label). Maybe you have any idea.
    Thanks 🙂

    • Hi Saskia,
      Sorry for the delay in responding, we do not monitor these comments for responses often.
      Did you get this resolved? Perhaps the Date field in SharePoint you should set to default of empty or today’s date. Not sure if that would resolve this, I have not tried it but happy to try to help.

      Let us know if you still need help on this, happy to try 🙂

      Thank you
      Cognillo Team

  3. I was thrilled to see this article, and after implementing it as a PoC, testing revealed that using the rich-text column in the content type metadata does not enable rich-text completely through to the SharePoint form level. I’ve noticed that only when the columns exist within a “List” does this work correctly. This article uses a “Document” content type which might be where things get cross-footed. Have you run into this, or do you have thoughts on how to use a “List” as the basis for the metadata columns?

    • Hi Rob,
      Sorry for the delay in responding, we do not monitor these comments for responses often.
      Did you get this resolve?
      Let us know if you still need help and happy to try to assist!

      Thank you
      Cognillo Team

Leave a Reply

Your email address will not be published. Required fields are marked *

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