How to export web part in Sharepoint Online Using CSOM?

Hello SharePointers,

In this blog ,we will see how to export web part in SharePoint Online using CSOM code.

using (ClientContext ctx = new ClientContext(“https://my.sharepoint.com”)) {
SecureString password = new SecureString();

ctx.Credentials = new SharePointOnlineCredentials(“name@my.onmicrosoft.com”, password);
File file = ctx.Web.GetFileByServerRelativeUrl(“/pages/mycustom.aspx”);
LimitedWebPartManager mgr= file.GetLimitedWebPartManager(PersonalizationScope.Shared);
Guid webPartId = new Guid(“your GUID”);
ClientResult webPartXml = mgr.ExportWebPart(webPartId);
ctx.ExecuteQuery();

Happy SharePointing 🙂

Leave a Reply

Your email address will not be published.