How to Change the Document Template in SharePoint Document Library?

Requirement: Change document template in SharePoint document library.

How to Add New Document Template in SharePoint?

How do I add templates to a SharePoint document library? To add a document template to the SharePoint document library, we’ve to first upload a new document template to SharePoint and then change the document template URL of the SharePoint document library from Document Library Settings >> Advanced Settings.

add new document template sharepoint

PowerShell to upload a new document template to SharePoint

Here is how to add a template to a document library in SharePoint using PowerShell:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
$DocumentTemplatePath="C:\Docs\Crescent Invoice Template V3.docx"

Try {
    #Get the Web and document Library
    $Web = Get-SPWeb $SiteURL
    $DocumentLibrary = $Web.Lists.TryGetList($DocumentLibraryName)
    #Check Cotent type and document template exists
    If($DocumentLibrary -ne $null -and [System.IO.File]::Exists($DocumentTemplatePath))
        #Get the Template File
     $TemplateFile =(Get-ChildItem $DocumentTemplatePath).OpenRead()

        #Get the Template File Name
        $DocumentTemplateFileName = [System.IO.Path]::GetFileName($DocumentTemplatePath)

        #Upload the document Template 
        $DocumentTemplate = $DocumentLibrary.RootFolder.SubFolders["Forms"].Files.Add($DocumentTemplateFileName, $TemplateFile,$True)

        #Set Document Template of the Content type
     $DocumentLibrary.DocumentTemplateUrl = $DocumentTemplate.URL

        Write-Host -f Green "Added Document Template $DocumentTemplateFileName to $DocumentLibraryName"
        Write-host -f Yellow "Cannot find Document Library $DocumentLibraryName or document template file $DocumentTemplatePath!"
Catch {
    write-host -f Red "Error Adding Template to Document Library!" $_.Exception.Message

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

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