当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 如何更改SharePoint文档库中的文档模板?

作者:精品下载站 日期:2024-12-14 14:53:54 浏览:15 分类:玩电脑

如何更改SharePoint文档库中的文档模板?


要求:更改SharePoint文档库中的文档模板。

如何在 SharePoint 中添加新文档模板?

如何将模板添加到 SharePoint 文档库?要将文档模板添加到 SharePoint 文档库,我们必须首先将新文档模板上传到 SharePoint,然后从文档库设置 >> 高级设置更改 SharePoint 文档库的文档模板 URL。

[玩转系统] 如何更改SharePoint文档库中的文档模板?

PowerShell 将新文档模板上传到 SharePoint

以下是如何使用 PowerShell 将模板添加到 SharePoint 中的文档库:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Parameters
$SiteURL="https://intranet.crescent.com"
$DocumentLibraryName="Invoices"
$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
        $DocumentLibrary.update()

        Write-Host -f Green "Added Document Template $DocumentTemplateFileName to $DocumentLibraryName"
    }
    Else
    {
        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
}

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯