How to add Webpart in a Page in Office 365 using CSOM ?
In this article, we will talk bout the site provisioning technique which is followed in Office 365 app model. you can add web part to SharePoint page using CSOM code. Below is the sample piece of code to achieve the same.
var context = new SP.ClientContext(webUrl);
var web = context.get_web();
var page= web.getFileByServerRelativeUrl(webUrl + pageUrl);
var webPartMgr = page.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);
var webPartDefine = webPartMgr.importWebPart(webPartXml);
var webPart = webPartDefine.get_webPart();
webPartMgr.addWebPart(webPart, zoneId, zoneIndex);
context.load(webPart);
context.executeQueryAsync(
function() {
Success(webPart);
},
Error
);
Do visit my other blogs on office365 below.
Remove Webpart in a Page in Office 365 using CSOM
Apply Site Logo In Office 365 using CSOM Code
Set Alternate CSS URL in Office 365 using CSOM
Set Theme to a site in SharePoint Online Or Office 365 programmatically using CSOM
Happy SharePointing Folks… Hope it helps you guys!!