A Better Way to Create New Office Documents

Image

March 1, 2023

Create New Office Documents from Templates in SharePoint – No content type

SharePoint is a great place for storing documents; what about creating documents? Yes, SharePoint also facilitates creating documents as well... and with a little work, you can make it very convenient for people to create documents based on your organization's standard templates. If you need to convert paper documents into digital documents, the software over on FilecenterDMS.com, if implemented in your business, could prove very beneficial in backing up and streamlining important information. Having digital files also makes it much easier when working in an office environment. Whilst paper can easily be lost, digital files are more difficult to lose. Additionally, when working in business, other staff members may require some files you've been working on. It is much easier sending large files fast over the internet, than having to copy a paper document to give to them.

As businesses grow they often amass a number of Office templates so that content can quickly and easily be reused. Businesses using SharePoint will often create a content type for each template. This involves specifying metadata and configuring where the document template is located. Then, once the content type is configured, you can associate it with a library, leaving a convenient way to create new documents based on the template... and you didn't have to leave SharePoint! Simply click New and the Content Types available in the library are presented. This is shown in Figure 1.

MM_201603_F1.png
Figure 1 - New Document from content types in a library

This approach works very well, presenting the user with the types of documents that are appropriate for this library. There might be occasions when you still need to create new documents in SharePoint (utilizing your custom templates) but don't want to create a content type for each template. You might have hundreds of contract templates (for example) that can leverage the same underlying content type.

Recall that when working in Windows Explorer, double clicking on a template file causes Office to create a new document based on that template; Create is the default action for that file type. But how does this work within SharePoint? When you click on a document template in SharePoint, the template is loaded into the appropriate editor; which is not the desired behavior. We want SharePoint to create a new document from that template, not open the template for editing. Here's how to get around this.

Implementation

Implementing this involves the following steps:

1. Store all your templates in a SharePoint library
2. Create a custom style template to implement the "create document behavior".
3. Create a dedicated page to present the templates.
4. Add a content query web part to display the templates to users.

Step #1

Begin by storing all the document templates in a dedicated library. I added a description column in the library that I will use to display just below the template title.

Step #2

Next customize the ItemStyle template in SharePoint. I'll use this when I add the content query web part to the page. To add the custom style, open .../Style Library/XSL Style Sheets/ItemStyle.xsl and add an additional template called DocumentTemplates.  The Customized style displays the results so that when a document template is clicked on, SharePoint will create an instance of the document template as a new document. This is accomplished by adding some javascript around the link to the document. This addition will be shown as a new style option in the Content Query Web Part settings.

MM_201603_F5.png

Steps #3 and #4

Next, I created a new page and added a content query web part. In the Tool setting of the web part, I set the query to look in the document library where my templates library is stored and specified that the list type was "Document Library" - Figure 2.

MM_201603_F2.png
Figure 2 - Query Settings

In the presentation settings for the web part, I specified "DocumentTemplates" as the Item style to use. This is the custom style that was added to the itemStyle XSLT file earlier. See Figure 3 - Content Query Presentation Settings

MM_201603_F3.png
Figure 3 - Content Query Presentation Settings

Once I saved the web part settings and the page, I could see my changes.  The final presentation is shown below. Clicking on any one of the documents opens a new instance of the template using the appropriate Office client.

Figure 4 - Templates presented on a page

Summary

This article showed how to customize the display and functionality of the content query web part.  With only a few lines of XSLT and a single line of javascript we changed the default behavior; clicking on the document template now results in the creation of a new document based on the underling template. This provides a good user experience and will make it easier for people to find and reuse Office templates that are stored in SharePoint.