***我使用SharePoint Powershell(2013)将webpart添加到页面
*** Affer从powershell添加了webpart成功,然后我转到页面,我看到webpart被添加到页面中(我还在Web部件页维护中看到了webpart)
***但是当我按编辑模式显示页面时,我找不到网页部分。
***你能帮我解决一下如何从powershell添加webpart,但是我仍然可以在网页浏览器的页面编辑模式下编辑webpart吗?
这是我的powershell脚本:
function NewGuid(){
$id = [System.Guid]::NewGuid().ToString()
return "g_" + $id.Replace("-","_")
}
function Add-ContentEditorWebPart()
{
$SiteURL = "https://insiderdev.connorgp.com"
$pageUrl = "https://insiderdev.connorgp.com/ConnorGroup/SitePages/NhanTest1.aspx"
$webpartzone = "Header"
$index = 1
$title = "Content Editor"
$site = new-object Microsoft.SharePoint.SPSite($SiteURL)
$web=$site.OpenWeb()
$webpartmanager = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$webpart = new-object Microsoft.SharePoint.WebPartPages.ContentEditorWebPart
$webpart.ChromeType = "None"
$webpart.Title = $title
$webpart.ID = NewGuid
$webpart.FrameType = "None"
$webpart.CatalogIconImageUrl = "/_layouts/15/images/mscontl.gif"
$webpart.PartImageLarge = "/_layouts/15/images/mscontl.gif"
$content = "Test Webpart added"
$docXml = New-Object System.Xml.XmlDocument
$contentXml = $docXml.CreateElement("Content")
$contentXml.set_InnerText($content)
$docXml.AppendChild($contentXml)
$webpart.Content = $contentXml
$webpartmanager.AddWebPart($webpart, $webpartzone, $index)
$web.Close()
$site.Close()
}
Add-ContentEditorWebPart