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?
To add a document template in 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 SharePoint:
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

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.