Add Wiki Page Library pages (not the publishing wiki) with PowerShell CSOM SharePoint 2013

混江龙づ霸主 提交于 2020-01-03 01:13:05

问题


Made a Wiki Page Library (not the publishing wiki) and can add pages with content like below, but when the page renders there is no SharePoint Chrome, just my content shows up. here is code. I it seems there may be one more property to add so master page takes effect?

$FileCreationInformation = New-Object Microsoft.SharePoint.Client.FileCreationInformation 
        $FileCreationInformation.Url = $FileRef
        $FileCreationInformation.Overwrite = $true
        $FileCreationInformation.Content = [System.Text.Encoding]::UTF8.GetBytes($HTMLPageContent) 
        $wikiFile = $WikiPageList.RootFolder.Files.Add($FileCreationInformation)
        $ClientContext.Load($wikiFile)  
        $ClientContext.ExecuteQuery() 

回答1:


How to create a page in Wiki Page Library using CSOM in SharePoint 2013

Use Utility.CreateWikiPageInContextWeb method to create a page in Wiki Page Library:

Function Create-WikiPage([Microsoft.SharePoint.Client.ClientContext]$Context,[string]$WikiLibraryTitle,[string]$PageName,[string]$PageContent)
{
    $wikiLibrary = $Context.Web.Lists.GetByTitle($wikiLibraryTitle)
    $Context.Load($wikiLibrary.RootFolder)
    $Context.ExecuteQuery()

    $wikiPageInfo = New-Object Microsoft.SharePoint.Client.Utilities.WikiPageCreationInformation
    $wikiPageInfo.WikiHtmlContent = $PageContent
    $wikiPageInfo.ServerRelativeUrl = [String]::Format("{0}/{1}", $wikiLibrary.RootFolder.ServerRelativeUrl, $PageName)
    $wikiFile = [Microsoft.SharePoint.Client.Utilities.Utility]::CreateWikiPageInContextWeb($Context, $wikiPageInfo)
    $context.ExecuteQuery()   
}

Usage

$context = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
Create-WikiPage -Context $Context -WikiLibraryTitle "KBList" -PageName "Welcome.aspx" -PageContent "Welcome to the SharePoint!"
$context.Dispose()


来源:https://stackoverflow.com/questions/26789829/add-wiki-page-library-pages-not-the-publishing-wiki-with-powershell-csom-share

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!