How to remove 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 remove web part from a  SharePoint page using CSOM code. Below is the sample piece of code to achieve the same.

Please visit my another article to add a webpart to a Sharepoint page using CSOM code.

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);

context .Load(webPartMgr.WebParts);
context .ExecuteQuery();
if (webPartMgr .WebParts.Count == 0)
throw new Exception(“No web parts found”);

var webPartDefinition = limitedWebPartManager.getById(WebPartGuid);
webPartDefinition.deleteWebPart(); 
clientContext.executeQueryAsync(Function.createDelegate(this, this.onRemoveSucceeded), Function.createDelegate(this, this.onRemoveFailed));

Do visit my other blogs on office365 below.

Add 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!!

Leave a Reply

Your email address will not be published. Required fields are marked *