简体   繁体   中英

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

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() 

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()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM