2

I am adding a web part using the following code and xml:

string xemelek = "<?xml version='1.0' encoding=\"utf-8\"?><webParts><webPart xmlns='http://schemas.microsoft.com/WebPart/v3'><metaData><type name='Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' /><importErrorMessage>Cannot import this Web Part.</importErrorMessage></metaData><data><properties><property name='ListUrl' type='string' /><property name='ListId' type='System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'>757981FB-184A-441B-952D-9434BE33DC85</property><property name='ListName' type='string'>{757981FB-184A-441B-952D-9434BE33DC85}</property></properties></data></webPart></webParts>";
        
WebPartDefinition newWebiie = wpm.ImportWebPart(xemelek2);
WebPartDefinition webpartie = wpm.AddWebPart(newWebiie.WebPart, "ms-comm-homeWelcome ms-core-defaultFont", 0);
ctx.Load(newWebiie);
ctx.ExecuteQuery();

Whatever zoneId I use, the webpart always lands at the bottom of the page: enter image description here

Inspect element shows the following zones: enter image description here

What I tried so far:

  • "Rich Content" - adds but at the bottom
  • "ms-rte-layoutszone-outer" - adds but at the bottom
  • "ms-rte-layoutszone-inner-editable ms-rtestate-write" - adds but at the bottom
  • "mainContent" - adds at the bottom
  • "wpz" - copied from a post on Wiki Page, did not work, no surprise
  • "Zone 2", Index 0 and 3 - adds at the bottom
  • "Top", Index 0 and 10 - adds at the bottom

I have set ZoneIndex to 0 and this is the only web part in this zone, but this seems to have no effect.

How can I set the web part to be just under the page title like this?: enter image description here

Settings from a manually added web part: enter image description here

The same behaviour can be observed on multiple pages and several sites (all that I tested).

3
  • AddWebPart(newWebiie.WebPart, "ms-comm-homeWelcome ms-core-defaultFont", 0);, 2nd paramter in addwebpart is defined the zone of it... You can put Bottom or Main instead of the ms-comm...
    – Waqas Sarwar MVP
    Commented Dec 8, 2015 at 22:24
  • Thanks Waqas, but I tried multiple options for the 2nd parameter, including Main and there is COMPLETELY no change whatsoever in the location of the webpart. To be clear, I do not move the web part, I re-add with every attempt.
    – grisha
    Commented Dec 9, 2015 at 8:45
  • One more observation - I suspect that the web parts are always added to the zone called "Bottom" regardless of the second parameter. Any ideas why the parameter could be ignored?
    – grisha
    Commented Dec 9, 2015 at 8:52

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.