1

Is there any way to retrieve the webpartxml using csom. I'm able to get the WebPartDefinition of all web parts in a page using LimitedWebPartManager class but WebPartDefinition object or properties.FieldValues doesn't contain the Webpartxml. My intension is to replicate this webpart in a separate site collection using the webpartxml.

1

Look at this: https://blog.mastykarz.nl/export-web-parts-csom/ (Source)

You would have to export the webpart, then import in the site you choose. Like this (this excerpt coming from above link):

using (ClientContext ctx = new ClientContext("https://contoso.sharepoint.com")) {  
  SecureString password = new SecureString();
  // setting password omitted for brevity
  ctx.Credentials = new SharePointOnlineCredentials("admin@contoso.onmicrosoft.com", password);
  File file = ctx.Web.GetFileByServerRelativeUrl("/pages/default.aspx");
  LimitedWebPartManager wpMgr = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
  Guid webPartId = new Guid("468a7c31-053b-41b3-9e7e-d658a3ecb7fc");
  ClientResult<string> webPartXml = wpMgr.ExportWebPart(webPartId);
  ctx.ExecuteQuery();



  // Web Part XML: webPartXml.Value

}
  • I'm getting this error on wpMgr.ExportWebPart: Method "ExportWebPart" does not exist. Is this method only available to SP Online as I'm trying to fetch webpartxml from on-prem SP. – Adi S Aug 21 '17 at 13:30
  • Also, I am trying to use the GetWebPart2 method from "/_vti_bin/WebPartPages.asmx" service by making a soap call but it's giving me a 401 unauthorized error. – Adi S Aug 21 '17 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.