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.
sharepoint web-parts
add a comment |
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.
sharepoint web-parts
Just to make sure: after running this snippet, did you invoke oFile.update() and executeQueryAsync() on the context?
– Szab
Nov 8 at 15:39
add a comment |
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.
sharepoint web-parts
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
sharepoint web-parts
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
add a comment |
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
add a comment |
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
Good point for theupdate()
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 thePageExtensions
code on PnP-Sites-Core
– spiderman77
yesterday
add a comment |
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
Good point for theupdate()
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 thePageExtensions
code on PnP-Sites-Core
– spiderman77
yesterday
add a comment |
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
Good point for theupdate()
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 thePageExtensions
code on PnP-Sites-Core
– spiderman77
yesterday
add a comment |
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
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
answered Nov 8 at 15:47
Szab
719414
719414
Good point for theupdate()
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 thePageExtensions
code on PnP-Sites-Core
– spiderman77
yesterday
add a comment |
Good point for theupdate()
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 thePageExtensions
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
Just to make sure: after running this snippet, did you invoke oFile.update() and executeQueryAsync() on the context?
– Szab
Nov 8 at 15:39