8

How to get Web Part Zone Id via CSOM? WebPart has property ZoneIndex but no ZoneId while WebPartDefinition has method MoveWebPartTo(string zoneID, int zoneIndex) but lacks methods to retrieve the ZoneId.

server-side API has WebPart.ZoneID.

  • Same for REST it seems, ref: /_api/web/getFileByServerRelativeUrl('/SitePages/Home.aspx')/GetLimitedWebPartManager()/WebParts – eirikb Apr 14 '14 at 17:14
  • sorry for the mistake – Salvatore Di Fazio Apr 22 '14 at 14:44
2

For those just finding this now, the current version (16.1) of the Microsoft SharePoint Online client object model now includes this property on the WebPartDefinition class.

http://dev.office.com/blogs/new-sharepoint-csom-version-released-for-Office-365

Note that this doesn't yet work on-prem, as the server side components don't yet expose this property.

1

You can do it by yourself using standard JavaScript or jQuery.

I show you an example how to recognize Web Part Zone Id.

So if we have a page layout like this:

enter image description here

Then we will have a page like this:

enter image description here

That is how the DOM looks like:

enter image description here enter image description here

What I suppose is that the MSOZoneCell_ is a standard prefix then after that is the Zone Id. So you can use that on your method to move your web part around.

  • Do you have idea how to retrieve the Zone Id (ZoneID property) specifically? – thomius Apr 22 '14 at 12:52
  • What about using the zoneIndex property of the SP.WebParts.WebPart object ? – Salvatore Di Fazio Apr 22 '14 at 12:56
  • ZoneIndex defines the order number inside a Zone, while ZoneID defines the Zone. For example, the third web part in "Left" web part zone has ZoneID "Left" and ZoneIndex 2. – thomius Apr 22 '14 at 14:04
  • I got you point... let me edit the answer and show you how to do that – Salvatore Di Fazio Apr 22 '14 at 14:28
  • 2
    I am accessing SharePoint from a remote server using client-side object model (Microsoft.SharePoint.Client.dll). If it is not possible to get ZoneID that way I think my secondary choice would be to use web services (msdn.microsoft.com/en-us/library/aa979489(v=office.12).aspx) where it seems to be possible to get the ZoneID at least for web parts which allow us to export the property values. – thomius Apr 22 '14 at 14:47
1

The REST API url needs to have the site url with full /sites/BusinessServices/ etc.

 https://TENANT/sites/HomePortal/_api/web/GetFileByServerRelativeUrl('/sites/HomePortal/Pages/ProductInfo.aspx')

And then need the personalizationscope when getting webparts :

 https://TENANT/sites/HomePortal/_api/web/GetFileByServerRelativeUrl('/sites/HomePortal/Pages/ProductInfo.aspx')/GetLimitedWebPartManager(1)

0 = Shared 1 = User

0

This works for me, using the SharePoint API.

var instance = SP.Ribbon.WebPartComponent.get_instance();
if (!instance.selectWebPartById(<id attribute from webpart element>) continue;
var zoneId = SP.Ribbon.WebPartComponent.get_activeWebPartZoneId();
0

Open the page for editing. Select the web part zone you want to know the ID for.

In the debug window, paste this:

var zoneId = SP.Ribbon.WebPartComponent.get_activeWebPartZoneId();

Thanks to Robbert Helling for getting me most of the way there

  • This always returns null for me – Bassie Feb 12 '18 at 2:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.