Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

Retrieve Webpart Proprties through CSOM in SharePoint 2010

My goal is to get an export of all webpart properties (including custom props) along with their values, from a page (urls provided through CSV).

I am following this approach: https://www.c-sharpcorner.com/article/retrieve-webparts-from-page-using-csom-with-powershell-for-s/

I am able to access all webparts sitting on a page as I can print their ID and Name, but getting an error in:

$ctx.Load($webpart.WebPart.Properties)
$ctx.ExecuteQuery() 

Error:

Exception calling "ExecuteQuery" with "0" argument(s): "Field or property "Properties" does not exist."

Appreciate your inputs / thoughts. Thanks.

question from:https://stackoverflow.com/questions/65661478/retrieve-webpart-proprties-through-csom-in-sharepoint-2010

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

SharePoint 2010 CSOM library didn't have the property "$webpart.WebPart.Proerties", if you can access the SharePoint Server, use SharePoint Server Object Model in PowerShell instead:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...