使用PowerShell CSOM SharePoint 2013添加Wiki页面库页面(而不是发布wiki)

时间:2014-11-06 21:36:18

标签: powershell sharepoint

制作一个Wiki页面库(不是发布维基),可以添加包含下面内容的页面,但是当页面呈现时没有SharePoint Chrome,只显示我的内容。这是代码。我似乎还有一个属性可以添加,因此母版页生效了吗?

$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 个答案:

答案 0 :(得分:1)

如何在SharePoint 2013中使用CSOM在Wiki页面库中创建页面

使用Utility.CreateWikiPageInContextWeb methodWiki 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()   
}

<强>用法

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