在 SharePoint Online 中使用 REST 创建文档集

Create document set with REST in SharePoint Online

我正在努力通过 REST API 在 SharePoint Online 中创建文档集。我发现这样做的唯一解决方案是按以下方式使用旧的 SharePoint 2010 REST 界面:

$http({
  method: "POST",
  url: url + "/_vti_bin/listdata.svc/" + listTitle,
  data: JSON.stringify(docSetOptions),
  headers: {
    "Accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",
    "X-RequestDigest": $('#__REQUESTDIGEST').val(),
    "Slug": _spPageContextInfo.siteServerRelativeUrl + "/" + url + docSetOptions.Path + "/" + docSetOptions.Title + "|" + docSetOptions.ContentTypeId,
  }
}).success(function (data, status, headers, config) {
  logtoconsole("document set created");
}).error(function (data, status, headers, config) {
  logtoconsole("document set error");
});

docSetOptions 是那些:

            var folder = new
            {
                Title = "foo",
                Path = "foo",
                ContentTypeId = "0x010050D9126DC6276846BF6D869EF2090EAD",
                ContentType = "SP.Data.Shared_x0020_DocumentsItem",
            };

id 是我的自定义内容类型的 id,派生自文档集。

来源:http://www.itidea.nl/index.php/create-a-document-set-using-jsom-and-rest/

这对我有用,但会创建一个 常规文件夹 。没有文件集。有人知道这在 SharePoint Online 中是否仍然有效吗? 我找到的唯一条目是关于 SharePoint 2013 的。

更新: 我 运行 针对 Premise Server 上的 SharePoint 2013 使用相同的脚本,它运行良好。文档集已创建。几个月前,微软改变了这一点。以前是可以的!

好的,我找到了解决办法。 一段时间以来,如果使用站点内容类型 ID,则不可能再通过 REST 创建文档集。 就我而言,我必须使用库中内容类型的 ID。 所以我去了我的图书馆设置,选择了我的内容类型并复制了它。这 id 有点不同。在我的例子中是 0x0120D5200085474276CB6D314E9BC0E6F067D47DBE。但在你的情况下,它看起来会有所不同。 如果我使用这个 id,我的文档集就创建成功了! 这花了我几个小时才发现。