SharePoint WebPart zoneId











up vote
0
down vote

favorite












I am using SharePoint online.

I want to use this CSOM code to add a WebPart to a page:



SP.File oFile = _web.GetFileByUrl(SiteUrl + "/SitePages/" + pageName);
oFile.CheckOut();
LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
var importedWebPart = limitedWebPartManager.ImportWebPart(webPartSchemaXml);
var webPart = limitedWebPartManager.AddWebPart(importedWebPart.WebPart, zoneid, zoneIndex);
oFile.Update();
await SiteCtx.ExecuteQueryAsync();
oFile.CheckIn(String.Empty, CheckinType.MinorCheckIn);


The problem is how to assign correct values to the zoneid string variable,
which is the name of the Web Part zone to which to add the Web Part.



When I run this code nothing happens!

(it doesn't add the WebPart to the page and I am suspecting it is related to the wrong zoneId).



I have read various post, ranging from accessing the code behind of the .aspx page trying to find the WebPartZone, accessing the WebPartManager class (which should list the ZoneId's but I don't know how to get it, since that I am using the LimitedWebPartManager class).



I have tried various values for zoneId, but at the moment none of them work:




  • Zone 1 (just a guess!)

  • Zone 2 (i see it in the right tab when manually editing the webpart through Edit page)


  • Body (with this the code worked some days ago! but now it doesn't anymore)

  • Header

  • Left

  • Bottom


What is the proper method of findind zoneId's?



EDIT



The page is the homepage, I have read somewhere that it is a wiki page so maybe it has different ZoneId's.










share|improve this question
























  • Just to make sure: after running this snippet, did you invoke oFile.update() and executeQueryAsync() on the context?
    – Szab
    Nov 8 at 15:39















up vote
0
down vote

favorite












I am using SharePoint online.

I want to use this CSOM code to add a WebPart to a page:



SP.File oFile = _web.GetFileByUrl(SiteUrl + "/SitePages/" + pageName);
oFile.CheckOut();
LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
var importedWebPart = limitedWebPartManager.ImportWebPart(webPartSchemaXml);
var webPart = limitedWebPartManager.AddWebPart(importedWebPart.WebPart, zoneid, zoneIndex);
oFile.Update();
await SiteCtx.ExecuteQueryAsync();
oFile.CheckIn(String.Empty, CheckinType.MinorCheckIn);


The problem is how to assign correct values to the zoneid string variable,
which is the name of the Web Part zone to which to add the Web Part.



When I run this code nothing happens!

(it doesn't add the WebPart to the page and I am suspecting it is related to the wrong zoneId).



I have read various post, ranging from accessing the code behind of the .aspx page trying to find the WebPartZone, accessing the WebPartManager class (which should list the ZoneId's but I don't know how to get it, since that I am using the LimitedWebPartManager class).



I have tried various values for zoneId, but at the moment none of them work:




  • Zone 1 (just a guess!)

  • Zone 2 (i see it in the right tab when manually editing the webpart through Edit page)


  • Body (with this the code worked some days ago! but now it doesn't anymore)

  • Header

  • Left

  • Bottom


What is the proper method of findind zoneId's?



EDIT



The page is the homepage, I have read somewhere that it is a wiki page so maybe it has different ZoneId's.










share|improve this question
























  • Just to make sure: after running this snippet, did you invoke oFile.update() and executeQueryAsync() on the context?
    – Szab
    Nov 8 at 15:39













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am using SharePoint online.

I want to use this CSOM code to add a WebPart to a page:



SP.File oFile = _web.GetFileByUrl(SiteUrl + "/SitePages/" + pageName);
oFile.CheckOut();
LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
var importedWebPart = limitedWebPartManager.ImportWebPart(webPartSchemaXml);
var webPart = limitedWebPartManager.AddWebPart(importedWebPart.WebPart, zoneid, zoneIndex);
oFile.Update();
await SiteCtx.ExecuteQueryAsync();
oFile.CheckIn(String.Empty, CheckinType.MinorCheckIn);


The problem is how to assign correct values to the zoneid string variable,
which is the name of the Web Part zone to which to add the Web Part.



When I run this code nothing happens!

(it doesn't add the WebPart to the page and I am suspecting it is related to the wrong zoneId).



I have read various post, ranging from accessing the code behind of the .aspx page trying to find the WebPartZone, accessing the WebPartManager class (which should list the ZoneId's but I don't know how to get it, since that I am using the LimitedWebPartManager class).



I have tried various values for zoneId, but at the moment none of them work:




  • Zone 1 (just a guess!)

  • Zone 2 (i see it in the right tab when manually editing the webpart through Edit page)


  • Body (with this the code worked some days ago! but now it doesn't anymore)

  • Header

  • Left

  • Bottom


What is the proper method of findind zoneId's?



EDIT



The page is the homepage, I have read somewhere that it is a wiki page so maybe it has different ZoneId's.










share|improve this question















I am using SharePoint online.

I want to use this CSOM code to add a WebPart to a page:



SP.File oFile = _web.GetFileByUrl(SiteUrl + "/SitePages/" + pageName);
oFile.CheckOut();
LimitedWebPartManager limitedWebPartManager = oFile.GetLimitedWebPartManager(PersonalizationScope.Shared);
var importedWebPart = limitedWebPartManager.ImportWebPart(webPartSchemaXml);
var webPart = limitedWebPartManager.AddWebPart(importedWebPart.WebPart, zoneid, zoneIndex);
oFile.Update();
await SiteCtx.ExecuteQueryAsync();
oFile.CheckIn(String.Empty, CheckinType.MinorCheckIn);


The problem is how to assign correct values to the zoneid string variable,
which is the name of the Web Part zone to which to add the Web Part.



When I run this code nothing happens!

(it doesn't add the WebPart to the page and I am suspecting it is related to the wrong zoneId).



I have read various post, ranging from accessing the code behind of the .aspx page trying to find the WebPartZone, accessing the WebPartManager class (which should list the ZoneId's but I don't know how to get it, since that I am using the LimitedWebPartManager class).



I have tried various values for zoneId, but at the moment none of them work:




  • Zone 1 (just a guess!)

  • Zone 2 (i see it in the right tab when manually editing the webpart through Edit page)


  • Body (with this the code worked some days ago! but now it doesn't anymore)

  • Header

  • Left

  • Bottom


What is the proper method of findind zoneId's?



EDIT



The page is the homepage, I have read somewhere that it is a wiki page so maybe it has different ZoneId's.







sharepoint web-parts






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 at 16:26

























asked Nov 8 at 11:04









spiderman77

8022926




8022926












  • Just to make sure: after running this snippet, did you invoke oFile.update() and executeQueryAsync() on the context?
    – Szab
    Nov 8 at 15:39


















  • Just to make sure: after running this snippet, did you invoke oFile.update() and executeQueryAsync() on the context?
    – Szab
    Nov 8 at 15:39
















Just to make sure: after running this snippet, did you invoke oFile.update() and executeQueryAsync() on the context?
– Szab
Nov 8 at 15:39




Just to make sure: after running this snippet, did you invoke oFile.update() and executeQueryAsync() on the context?
– Szab
Nov 8 at 15:39












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










ZoneIDs might be different depending on the page layout, but usually out-of-the-box SharePoint layouts use the following ID's for webpart zones:




  • TitleBar

  • Header

  • LeftColumn

  • MiddleColumn

  • RightColumn

  • Footer


Make sure that you invoke the update() method on your file object and executeQueryAsync() method on your context after importing the webpart - the latter function especially is responsible for sending the request to server and applying your changes.



Here's a nice article about adding webparts to pages programatically: How to programmatically add a ClientSide Web Part to a SharePoint page






share|improve this answer





















  • Good point for the update() method call, I missed it and now I have inserted the line. I hoped that would be resolutive, but it hasn't been. Maybe an important edit: the page I am trying to add the webpart is the homepage and somewhere I have read that it is a wiki page layout.
    – spiderman77
    Nov 13 at 16:19










  • Oh, that's a bit different then, as there are no zones on webpart pages and you inject webparts straight into the wiki page content. You have to add the webpart to the page and then inject it into the page's rich content's markup. Take a look at this link: c-sharpcorner.com/blogs/…
    – Szab
    Nov 13 at 17:54






  • 1




    Thank Szab, that have pointed me to the right direction: but I have used the PageExtensions code on PnP-Sites-Core
    – spiderman77
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206439%2fsharepoint-webpart-zoneid%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










ZoneIDs might be different depending on the page layout, but usually out-of-the-box SharePoint layouts use the following ID's for webpart zones:




  • TitleBar

  • Header

  • LeftColumn

  • MiddleColumn

  • RightColumn

  • Footer


Make sure that you invoke the update() method on your file object and executeQueryAsync() method on your context after importing the webpart - the latter function especially is responsible for sending the request to server and applying your changes.



Here's a nice article about adding webparts to pages programatically: How to programmatically add a ClientSide Web Part to a SharePoint page






share|improve this answer





















  • Good point for the update() method call, I missed it and now I have inserted the line. I hoped that would be resolutive, but it hasn't been. Maybe an important edit: the page I am trying to add the webpart is the homepage and somewhere I have read that it is a wiki page layout.
    – spiderman77
    Nov 13 at 16:19










  • Oh, that's a bit different then, as there are no zones on webpart pages and you inject webparts straight into the wiki page content. You have to add the webpart to the page and then inject it into the page's rich content's markup. Take a look at this link: c-sharpcorner.com/blogs/…
    – Szab
    Nov 13 at 17:54






  • 1




    Thank Szab, that have pointed me to the right direction: but I have used the PageExtensions code on PnP-Sites-Core
    – spiderman77
    yesterday















up vote
1
down vote



accepted










ZoneIDs might be different depending on the page layout, but usually out-of-the-box SharePoint layouts use the following ID's for webpart zones:




  • TitleBar

  • Header

  • LeftColumn

  • MiddleColumn

  • RightColumn

  • Footer


Make sure that you invoke the update() method on your file object and executeQueryAsync() method on your context after importing the webpart - the latter function especially is responsible for sending the request to server and applying your changes.



Here's a nice article about adding webparts to pages programatically: How to programmatically add a ClientSide Web Part to a SharePoint page






share|improve this answer





















  • Good point for the update() method call, I missed it and now I have inserted the line. I hoped that would be resolutive, but it hasn't been. Maybe an important edit: the page I am trying to add the webpart is the homepage and somewhere I have read that it is a wiki page layout.
    – spiderman77
    Nov 13 at 16:19










  • Oh, that's a bit different then, as there are no zones on webpart pages and you inject webparts straight into the wiki page content. You have to add the webpart to the page and then inject it into the page's rich content's markup. Take a look at this link: c-sharpcorner.com/blogs/…
    – Szab
    Nov 13 at 17:54






  • 1




    Thank Szab, that have pointed me to the right direction: but I have used the PageExtensions code on PnP-Sites-Core
    – spiderman77
    yesterday













up vote
1
down vote



accepted







up vote
1
down vote



accepted






ZoneIDs might be different depending on the page layout, but usually out-of-the-box SharePoint layouts use the following ID's for webpart zones:




  • TitleBar

  • Header

  • LeftColumn

  • MiddleColumn

  • RightColumn

  • Footer


Make sure that you invoke the update() method on your file object and executeQueryAsync() method on your context after importing the webpart - the latter function especially is responsible for sending the request to server and applying your changes.



Here's a nice article about adding webparts to pages programatically: How to programmatically add a ClientSide Web Part to a SharePoint page






share|improve this answer












ZoneIDs might be different depending on the page layout, but usually out-of-the-box SharePoint layouts use the following ID's for webpart zones:




  • TitleBar

  • Header

  • LeftColumn

  • MiddleColumn

  • RightColumn

  • Footer


Make sure that you invoke the update() method on your file object and executeQueryAsync() method on your context after importing the webpart - the latter function especially is responsible for sending the request to server and applying your changes.



Here's a nice article about adding webparts to pages programatically: How to programmatically add a ClientSide Web Part to a SharePoint page







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 8 at 15:47









Szab

719414




719414












  • Good point for the update() method call, I missed it and now I have inserted the line. I hoped that would be resolutive, but it hasn't been. Maybe an important edit: the page I am trying to add the webpart is the homepage and somewhere I have read that it is a wiki page layout.
    – spiderman77
    Nov 13 at 16:19










  • Oh, that's a bit different then, as there are no zones on webpart pages and you inject webparts straight into the wiki page content. You have to add the webpart to the page and then inject it into the page's rich content's markup. Take a look at this link: c-sharpcorner.com/blogs/…
    – Szab
    Nov 13 at 17:54






  • 1




    Thank Szab, that have pointed me to the right direction: but I have used the PageExtensions code on PnP-Sites-Core
    – spiderman77
    yesterday


















  • Good point for the update() method call, I missed it and now I have inserted the line. I hoped that would be resolutive, but it hasn't been. Maybe an important edit: the page I am trying to add the webpart is the homepage and somewhere I have read that it is a wiki page layout.
    – spiderman77
    Nov 13 at 16:19










  • Oh, that's a bit different then, as there are no zones on webpart pages and you inject webparts straight into the wiki page content. You have to add the webpart to the page and then inject it into the page's rich content's markup. Take a look at this link: c-sharpcorner.com/blogs/…
    – Szab
    Nov 13 at 17:54






  • 1




    Thank Szab, that have pointed me to the right direction: but I have used the PageExtensions code on PnP-Sites-Core
    – spiderman77
    yesterday
















Good point for the update() method call, I missed it and now I have inserted the line. I hoped that would be resolutive, but it hasn't been. Maybe an important edit: the page I am trying to add the webpart is the homepage and somewhere I have read that it is a wiki page layout.
– spiderman77
Nov 13 at 16:19




Good point for the update() method call, I missed it and now I have inserted the line. I hoped that would be resolutive, but it hasn't been. Maybe an important edit: the page I am trying to add the webpart is the homepage and somewhere I have read that it is a wiki page layout.
– spiderman77
Nov 13 at 16:19












Oh, that's a bit different then, as there are no zones on webpart pages and you inject webparts straight into the wiki page content. You have to add the webpart to the page and then inject it into the page's rich content's markup. Take a look at this link: c-sharpcorner.com/blogs/…
– Szab
Nov 13 at 17:54




Oh, that's a bit different then, as there are no zones on webpart pages and you inject webparts straight into the wiki page content. You have to add the webpart to the page and then inject it into the page's rich content's markup. Take a look at this link: c-sharpcorner.com/blogs/…
– Szab
Nov 13 at 17:54




1




1




Thank Szab, that have pointed me to the right direction: but I have used the PageExtensions code on PnP-Sites-Core
– spiderman77
yesterday




Thank Szab, that have pointed me to the right direction: but I have used the PageExtensions code on PnP-Sites-Core
– spiderman77
yesterday


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206439%2fsharepoint-webpart-zoneid%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff