【问题标题】:convert ssom to csom of Adding Document Librarty to Sharepoint 2013将 ssom 转换为将文档库添加到 Sharepoint 2013 的 csom
【发布时间】:2021-10-08 20:24:55
【问题描述】:

我正在尝试将以下代码 SSOM 转换为向 SharePoint 2013 页面添加文档库的 CSOM。

SSOM

SPFile ofile = web.Getfile("Pages/Home.aspx");
using(SPLimitedWebPartManager wpm = ofile.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
    SPList oList = web.Lists["TestDocument"];
    SPView oView = oList.Views["WebPart"];
    XsltListViewWebPart aWp = new XsltListViewWebPart
    {
        ListName = oList.ID.ToString("B").ToUpper(),
        Title = "Practice Announcements",
        ViewContentTypeId = oView.ContentTypeId.ToString(),
        ViewGuid = oView.ID.ToString("B").ToUpper(),
        Width = "400px",
        ChromeType = PartChromeType.TitleOnly
    };
    wpm.AddWebPart(aWp,"CenterLeftColumn",1);
    oList.Update();
}

任何文章,链接都可以提供帮助

【问题讨论】:

    标签: sharepoint-2013 web-parts csom


    【解决方案1】:

    您应该为文档库使用 Webpart XML 内容,当我将 listviewwebparts 添加到 CSOM 中的页面时,下面的 XML 架构与我一起使用

    <?xml version="1.0" encoding="utf-8" ?>
    <webParts>
      <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
        <metaData>
          <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
          <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
        </metaData>
        <data>
          <properties>
            <property name="ListUrl" type="string">Shared%20Documents</property>
            <property name="MissingAssembly" type="string">Cannot import this Web Part.</property>
          </properties>
        </data>
      </webPart>
    </webParts>
    

    示例代码:

                var wpXML = @"<?xml version='1.0' encoding='utf-8' ?>
    <webParts>
      <webPart xmlns='http://schemas.microsoft.com/WebPart/v3'>
        <metaData>
          <type name='Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' />
          <importErrorMessage>Cannot import this Web Part.</importErrorMessage>
        </metaData>
        <data>
          <properties>
            <property name='ListUrl' type='string'>Shared%20Documents</property>
            <property name='MissingAssembly' type='string'>Cannot import this Web Part.</property>
          </properties>
        </data>
      </webPart>
    </webParts>";
    
                var page = ctx.Web.GetFileByServerRelativeUrl("/sites/test/SitePages/wiki1.aspx");
    
                var wpm = page.GetLimitedWebPartManager(PersonalizationScope.Shared);
                ctx.Load(wpm);
                ctx.ExecuteQuery();
    
                var importedWebPart = wpm.ImportWebPart(wpXML);
                var webPart = wpm.AddWebPart(importedWebPart.WebPart, "mainContent", 0);
                ctx.ExecuteQuery();
    

    【讨论】:

    • 谢谢 Michael,我们可以不用 XML 吗?有没有其他方法可以在不使用 XML 的情况下将文档库添加到页面中
    • 据我所知,我们必须使用 XML 将 Web 部件插入页面。
    • 感谢 Michael,您提供的代码按预期工作。添加文档库时可以选择默认视图吗?
    猜你喜欢
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 2015-03-28
    • 1970-01-01
    • 2019-07-07
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多