问题描述
我的目标是从页面(通过 CSV 提供的网址)导出所有 webpart 属性(包括自定义道具)及其值。
我正在遵循这种方法: https://www.c-sharpcorner.com/article/retrieve-webparts-from-page-using-csom-with-powershell-for-s/
我可以访问页面上的所有 webpart,因为我可以打印它们的 ID 和名称,但出现错误:
$ctx.Load($webpart.WebPart.Properties)
$ctx.ExecuteQuery()
错误:
Exception calling "ExecuteQuery" with "0" argument(s): "Field or property "Properties" does not exist."
感谢您的意见/想法。谢谢。
解决方法
SharePoint 2010 CSOM 库没有属性“$webpart.WebPart.Proerties”,如果您可以访问 SharePoint Server,请改用 PowerShell 中的 SharePoint Server 对象模型:
Add-PSSnapin Microsoft.SharePoint.PowerShell
$SiteUrl = "http://www.yoursite.com"
$pageURL = "Pages/default.aspx"
$site = New-Object Microsoft.SharePoint.SPSite($SiteUrl)
$psite = New-Object Microsoft.SharePoint.Publishing.PublishingSite($site)
$web = Get-SPWeb $SiteUrl
$pweb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$wpm = $web.GetLimitedWebPartManager($pageURL,[System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
#List all the web parts
$wpm.WebParts | ft
#Get the details of the first web part
$wp = $wpm.WebParts[0]
$wp