Sep 20 2023 01:53 PM
I have created a PDF template named Shipping, inside a document library inside our SharePoint online, as follow:-
now i need to share this template with 20 document libraries, is there an easy way to do so?
Thanks
Sep 20 2023 10:53 PM
Hi @john john,
There are a few ways to add the same template to multiple document libraries in SharePoint Online, but I think that the best solution is using the Copy Template feature. It's the simplest way to do it.
You can also use PowerShell for that.
You can try to use this example (template):
$templateURL = "https://[your-site-url]/[document-library-URL]/[template-name].pdf"
$documentLibraries = @[
"https://[your-site-url]/[document-library-URL-1]",
"https://[your-site-url]/[document-library-URL-2]",
"https://[your-site-url]/[document-library-URL-3]"
]
foreach ($documentLibrary in $documentLibraries) {
$outputFile = "$documentLibrary/[template-name].pdf"
Copy-Item -Path $templateURL -Destination $outputFile -Force
}
To use this script, you will need to enter the values from youe environment.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
Sep 20 2023 11:06 PM
SolutionHi @john john ,
you can automate that if you use PnP Powershell.
First modify the "New" menu of one document library like you want them all to look. Then execute these Powershell commands
# Get the template
Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$listname="Name of the base document library"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$template=$view.NewDocumentTemplates
This will load the configuration of the "New" menu inside of the variable "$template". Keep the PowerShell window open and enter these lines
# If the library is on a different site than the other library
#Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$listname="Name of the documentlibrary you want to apply the template to"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$view.NewDocumentTemplates = $template
$view.Update()
Invoke-PnPQuery
That will apply the same "New" Menu to that other document library. It will not upload the document templates a second time but will configure both libraries to use the same template file.
Best Regards,
Sven
Sep 21 2023 08:00 AM
@SvenSieverding thanks a lot for your reply, i tested this on my test site and it worked well,, but before applying this to PROD , will this cause any drawbacks to the document libraries? since they will reference others libraries templates? do you have any documentations about those commands as i could not find any
Sep 21 2023 08:02 AM
@LeonPavesicThanks for the reply. i could not find the Templates section inside the document libraries settings, can you advice from where i can find it?
also your power shell script will create a copy of the templates, is there a way to have all templates referencing one main template, so when changing the main template all the underlying templates which reference the main template will get the change?
Sep 21 2023 11:19 PM
Hi @john john,
The Templates section in the document library settings is only available for classic SharePoint sites. In modern SharePoint sites, the templates are managed using the New Document menu.
To access the New Document menu, go to the document library where you want to add the template. Then, click the New button.
In the New Document menu, you will see a list of all of the templates that are available in the document library. To add a new template, click the + Add template button.
To create a template from an existing document, click the Create from existing button. Then, select the document that you want to use as the template.
To create a template from scratch, click the Create new button. Then, select the type of template that you want to create.
Once you have created the template, you can add it to the New Document menu by clicking the Add to New button.
To have all templates referencing one main template, you can use the following steps:
Here is a sample PowerShell script that you can use to copy the main template to each document library:
$templateURL = "https://[your-site-url]/[central-library-URL]/[template-name].pdf"
$documentLibraries = @[
"https://[your-site-url]/[document-library-URL-1]",
"https://[your-site-url]/[document-library-URL-2]",
"https://[your-site-url]/[document-library-URL-3]"
]
foreach ($documentLibrary in $documentLibraries) {
$outputFile = "$documentLibrary/[template-name].pdf"
Copy-Item -Path $templateURL -Destination $outputFile -Force
}
Here is a sample PnP PowerShell command that you can use to update the New Document Templates menu in each document library:
Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$templateURL = "https://[your-site-url]/[central-library-URL]/[template-name].pdf"
$documentLibraries = @[
"https://[your-site-url]/[document-library-URL-1]",
"https://[your-site-url]/[document-library-URL-2]",
"https://[your-site-url]/[document-library-URL-3]"
]
foreach ($documentLibrary in $documentLibraries) {
$view = Get-PnpView -List $documentLibrary | Where-Object {$_.DefaultView -eq $true}
$template = New-PnPListItemTemplate -Url $templateURL
$view.NewDocumentTemplates = $template
$view.Update()
Invoke-PnPQuery
}
Once you have run these scripts, all of the document libraries will reference the main template. When you make a change to the main template, the change will be reflected in all of the document libraries.
Please click Mark as Best Response & Like if my post helped you to solve your issue.
This will help others to find the correct solution easily. It also closes the item.
If the post was useful in other ways, please consider giving it Like.
Kindest regards,
Leon Pavesic
Sep 20 2023 11:06 PM
SolutionHi @john john ,
you can automate that if you use PnP Powershell.
First modify the "New" menu of one document library like you want them all to look. Then execute these Powershell commands
# Get the template
Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$listname="Name of the base document library"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$template=$view.NewDocumentTemplates
This will load the configuration of the "New" menu inside of the variable "$template". Keep the PowerShell window open and enter these lines
# If the library is on a different site than the other library
#Connect-PnPOnline https://<tenant>.sharepoint.com/sites/<site> -UseWebLogin
$listname="Name of the documentlibrary you want to apply the template to"
$view = Get-PnpView -List $listname | Where-Object {$_.DefaultView -eq $true}
$view.NewDocumentTemplates = $template
$view.Update()
Invoke-PnPQuery
That will apply the same "New" Menu to that other document library. It will not upload the document templates a second time but will configure both libraries to use the same template file.
Best Regards,
Sven