【问题标题】:Export SharePoint Webpart using csom使用 csom 导出 SharePoint Webpart
【发布时间】:2015-10-11 16:50:09
【问题描述】:

有谁知道是否可以在 Office 365 中使用 CSOM 导出 Web 部件。我想要启用的方案是将发布页面(嵌入了 Web 部件)从一个 Office 365 租户移动到另一个。我的初步研究表明,在客户端代码中这是不可能的 - 任何帮助表示赞赏。

【问题讨论】:

    标签: sharepoint sharepoint-online


    【解决方案1】:

    下面的代码应该可以解决问题。

     var limitedWebPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
            var webPartDefinitons = limitedWebPartManager.WebParts;
            clientContext.LoadAndExecute(webPartDefinitons);
            foreach (var webpartDefintion in webPartDefinitons)
            {
                try
                {
                    var webPartId = webpartDefintion.Id;
                    var webPartXML = limitedWebPartManager.ExportWebPart(webPartId);
                    clientContext.ExecuteQuery();
                    clientContext.Load(webpartDefintion, def => def.ZoneId, def => def.Id);
                    clientContext.LoadAndExecute(webpartDefintion.WebPart, w => w.Title, w => w.ZoneIndex, w => w.Properties);
    
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception);
                }
            }
    

    【讨论】:

    【解决方案2】:

    SharePoint 通过 CSOM 仅导出 LimitedWebPartManager。 它非常有限(因此得名),只能实现有限的动作。 (更改 WebPart 的标题,阅读信息)。

    但是,我建议您使用 /_vti_bin/webpartpages.asmx 服务。 (添加服务参考,http://yoursharepoint/_vti_bin/webpartpages.asmx

    var credentials = new NetworkCredential();
    credentials.UserName = "username";
    credentials.Password = "secret";
    credentials.Domain = "domain";
    
    var svc = new WebPartPagesSvc.WebPartPagesWebService();
    svc.Credentials = credentials;
    
    var result = svc.GetWebPartPage(filename, WebPartPages2Svc.SPWebServiceBehavior.Version3);
    
    Console.Write(result);
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-10-11
      • 2011-03-29
      • 2012-01-10
      • 1970-01-01
      • 2020-11-05
      • 2010-12-28
      • 2018-09-22
      • 2011-11-01
      • 2019-04-11
      相关资源
      最近更新 更多