ค้นหาเว็บไซต์

เพิ่มเทมเพลตเอกสารลงในประเภทเนื้อหาใน SharePoint โดยใช้ PowerShell


ข้อกำหนด: เชื่อมโยงเทมเพลตเอกสารกับประเภทเนื้อหาใน SharePoint

PowerShell เพื่อเพิ่มเทมเพลตเอกสารให้กับประเภทเนื้อหาใน SharePoint

นี่คือ PowerShell เพื่ออัปโหลดเทมเพลตเอกสารไปยังประเภทเนื้อหาใน SharePoint:


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Parameters
$SiteURL="https://intranet.crescent.com"
$ContentTypeName="Crescent Invoice Template V2"
$DocumentTemplatePath="C:\Temp\Crescent Invoice Template V3.docx"

Try {
    #Get the Web and Content Type
    $Web = Get-SPWeb $SiteURL
    $ContentType = $Web.ContentTypes | Where {$_.Name -eq $ContentTypeName}
 
    #Check Cotent type and document template exists
    If($ContentType -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 = $ContentType.ResourceFolder.Files.Add($DocumentTemplateFileName, $TemplateFile,$True)

        #Set Document Template of the Content type
        $contentType.DocumentTemplate = $DocumentTemplateFileName
        $contentType.UpdateIncludingSealedAndReadOnly($True)
  
        Write-Host -f Green "Added Document Template $DocumentTemplateFileName to $ContentTypeName"
    }
    Else
    {
        Write-host -f Yellow "Cannot find Content Type $ContentTypeName or document template file $DocumentTemplatePath!"
    }
}
Catch {
    write-host -f Red "Error Adding Document Template to Content Type!" $_.Exception.Message
}

บทความที่เกี่ยวข้อง