top of page
Writer's pictureKasper Larsen

Document templates in SharePoint Libraries - part 1 (classic)

Updated: Oct 13

Disclaimer: this blog post is about using document templates in an Enterprise/Provisioning scenario - not from an end user perspective.


This is part 1 of a serie of blog posts about the options we have when dealing with Document Templates


Recently I had a request from a customer about adding their own document templates to the "New" dropdown in the SharePoint Library.


The customer requested that any subsequent updates to the document template should be deployed to the existing libraries as painless as possible.


Option A: Using Content types to provide the document template

Previously the recommended way to add a document template to a library in a controlled manner, was to add the document template to the content type in the Content type gallery (aka the content type hub).


As any update to the content type in the Gallery was automatically pushed to the site collections this made it easy to update the document temple: Upload the updated version of the document template to the content type and hit "publish" and you were done.


This approach is no longer the obvious choice as Microsoft no longer pushes the changes to the site collections. Today the site collection admins are notified that the content type in the Gallery has been updated, and it is up the individual site collection to pull the update from the Gallery.


So how can we ensure that the document template/content type is updated on the relevant site collections?

Even If we know which Site Provisioning Templates are using this content type, then

it might not be sufficient as any site owner might have added this content type to one of the libraries on his/her site.


Can we use Search to find the sites using this content type?

We can use a query like contenttypeid:[ID of the content type in the Gallery]*, but unfortunately, it will only inform us about the sites where an item using that content type exists. In other words: sites where this content type has been added to a list/library but NOT used yet will not be detected.


Brute force always works but takes time and is ressource heavy. Iterate each site collection, use Get-PnPContentType to validate if the content type exists on this site. If that is the case, sync the most recent content type from the gallery using Add-PnPContentTypesFromContentTypeHub.


At the moment I am preferring the search-based approach as it is less resource intensive than the brute force. I usually set up an Azure Runbook to update/sync the content type to the sites, using the Content type ID from the Gallery as a parameter. This is a manual process and requires that the admin updating the content type knows that she is required to activate this runbook.

I would very much prefer a timer-based runbook that could figure up which of the content types in the gallery that have been updated recently and act accordingly. Unfortunately, I haven't yet found any way to detect the last published date for the content types. If you know how to get to that date, please let me know.


EDIT 03 Nov 2024:

at the recent Ask Sympraxis call Julie Turner showed a way more elegant solution, having the link in the Content Type pointing to a template file in the Contentype hub. This will ensure that we now only have to update the template file once, publish the content type in the hub, and after a few minutes the new template file is attached to the content type in the sites




When you add the content type to the library using the modern interface the library is switched to allowing management of content types:


This will change the "New" button to show this:


In most cases this is not really an issue as the library often is intended to "host" only one Content type and document template anyway. But if the requirement is that the document template must be added to the existing list of templates (as below) then we will have to use another approach.



In Part 2 we will have a look at using the modern approach (aka view.NewDocumentTemplates)


















60 views0 comments

Commentaires


bottom of page