private static void AddWebPartsToPublishingPage(PublishingPage page, ClientContext ctx, Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr, TokenParser parser) { foreach (var wp in page.WebParts) { string wpContentsTokenResolved = parser.ParseString(wp.Contents).Replace("<property name=\"JSLink\" type=\"string\">" + ctx.Site.ServerRelativeUrl,"<property name=\"JSLink\" type=\"string\">~sitecollection"); Microsoft.SharePoint.Client.WebParts.WebPart webPart = mgr.ImportWebPart(wpContentsTokenResolved).WebPart; Microsoft.SharePoint.Client.WebParts.WebPartDefinition definition = mgr.AddWebPart( webPart, wp.Zone, (int)wp.Order ); var webPartProperties = definition.WebPart.Properties; ctx.Load(definition.WebPart); ctx.Load(webPartProperties); ctx.ExecuteQuery(); if (wp.IsListViewWebPart) { AddListViewWebpart(ctx, wp, definition, webPartProperties, parser); } } }
private static void AddWebpartsToPublishingPage(PublishingPage page, ClientContext ctx, Microsoft.SharePoint.Client.WebParts.LimitedWebPartManager mgr) { foreach (var wp in page.WebParts) { string wpContentsTokenResolved = wp.Contents; Microsoft.SharePoint.Client.WebParts.WebPart webPart = mgr.ImportWebPart(wpContentsTokenResolved).WebPart; Microsoft.SharePoint.Client.WebParts.WebPartDefinition definition = mgr.AddWebPart( webPart, wp.Zone, (int)wp.Order ); var webPartProperties = definition.WebPart.Properties; ctx.Load(definition.WebPart); ctx.Load(webPartProperties); ctx.ExecuteQuery(); if (wp.IsListViewWebPart) { AddListViewWebpart(ctx, wp, definition, webPartProperties); } } }