0

When fetching a page in CSOM from a SharePoint add-in, how is it possible to fetch the ZoneId of a certain web part? With the "SPLimitedWebPartManager" you have a method "GetZoneID" (https://msdn.microsoft.com/EN-US/library/microsoft.sharepoint.webpartpages.splimitedwebpartmanager.getzoneid.aspx)

But of course you don't have that one available in CSOM. When checking the available methods on the "LimitedWebPartManager" I don't see anything that comes near to it:

https://msdn.microsoft.com/en-us/library/office/microsoft.sharepoint.client.webparts.limitedwebpartmanager_methods.aspx

Mathieu
  • 367
  • 3
  • 11

2 Answers2

0

Unfortunately SharePoint CSOM WebPart class does not expose ZoneId property.

As an alternative solution you could consider to consume SharePoint Web Services, in particular Web Part Pages Service, the following example demonstrates how to retrieve Web Part Zone Id property using WebPartPagesWebService.GetWebPartProperties2 method:

var pageUrl = "/Pages/default.aspx";

var webPartPagesProxy = new WebPartPagesWebService();
webPartPagesProxy.Url = webUri + "/_vti_bin/WebPartPages.asmx";
var result = webPartPagesProxy.GetWebPartProperties2(pageUrl,Storage.Shared, SPWebServiceBehavior.Version3);

var wpDoc = XDocument.Parse(result.OuterXml);
var zoneId = wpDoc.Descendants(XName.Get("ZoneID", @"http://schemas.microsoft.com/WebPart/v2")).First().Value;  
Vadim Gremyachev
  • 57,952
  • 20
  • 129
  • 193
0

I would like to add to the previous answer.

While it works for web parts using "http://schemas.microsoft.com/WebPart/v2", for the ones using "http://schemas.microsoft.com/WebPart/v3", which is most of them I believe, the Zone ID is not exposed.

For the web parts where you don't get the Zone ID your only option left is getting the page contents using GetWebPartPage web service and parsing it. Within the page you'll have the web part elements within "WebPartPages:WebPartZone" elements (each representing a different zone). These web part elements have the ID of the web part as well as the ZoneID within their main XML node. So you can use regex to fish it out. Here is a very simple regex (make sure you set the case-insensitive option on whatever environment you're running this on):

ZoneID="(.*?)".*?0a32c6f6-ee05-4c8e-ba7a-587c0c67c382

Serital
  • 343
  • 3
  • 13