Warm tip: This article is reproduced from stackoverflow.com, please click
microsoft-graph sharepoint sharepoint-2013 sharepoint-online

Not able to get webparts on a site page in Sharepoint

发布于 2020-04-16 12:02:09

Using the below code using CSOM, I'm not able to fetch the webparts of a page in Sharepoint.

Microsoft.SharePoint.Client.File oFile = this._ClientContext.Web.GetFileByServerRelativeUrl(myurl );
                LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
                this._ClientContext.Load(limitedWebPartManager.WebParts,
                 wps => wps.Include(
                 wp => wp.WebPart.Title,
                 wp => wp.Id,
                 wp => wp.WebPart.ExportMode,
                 wp => wp.WebPart.TitleUrl,
                 wp => wp.WebPart.Properties
                 ));
                this._ClientContext.Load(limitedWebPartManager.WebParts);
                this._ClientContext.ExecuteQuery();
                var areItemsavail = limitedWebPartManager.WebParts.AreItemsAvailable;
                var webpartcount = limitedWebPartManager.WebParts.Count;

The areItemsavail above shows true, while the webpartcount shows the value 0.
There are lot of webparts available on the dedicated page.
Is there any way to fetch/get the webparts on a Sharepoint Site Page using CSOM ?

Questioner
Rohit Kumar
Viewed
64
Lee_MSFT 2020-02-04 15:59

Which type of page you created?

webpart page:

enter image description here

publishing page:

enter image description here

not for modern page(site page) enter image description here