2

我正在使用 OfficeDev.Core 在 C# 中的提供程序托管加载项中的 sharepoint Online 中创建 DocumentSet“文件夹”。

我正在为 Sharepoint Online 使用最新的 CSOM C# 库:Microsoft.SharePoint.Client.dll V16.1.5813.1200 Microsoft.SharePoint.Client.DocumentManagement.dll V16.1.5813.1200

这几个月都运行良好,昨天我们注意到 Microsoft.SharePoint.Client.DocumentSet.DocumentSet 类的 Create 方法返回一个未知错误!

我使用具有最高权限的 AppOnly 访问令牌。

您有任何想法或解决方法来使用 CSOM 创建文档集吗?

谢谢

PS:我尝试使用 UI 创建这个文档集,它工作正常。  

4

2 回答 2

1

我在这篇文章中找到了解决方案:

https://sharepoint.stackexchange.com/questions/199336/creating-document-sets-with-sharepoint-csom-api/199718#199718

我在 2016 年 11 月 14 日星期一早上在我的租户身上遇到了同样的问题

文档集的创建突然停止工作

现有代码:

var devisCT = globalHostWeb.GetContentTypeByName(SPConstants.CTName_Devis);
dsQuoteFolder = rootFolder.CreateDocumentSet(folderName, devisCT.Id);

对我有用的解决方案是:

var devisCT = devisLib.GetContentTypeByName(SPConstants.CTName_Devis); 
dsQuoteFolder = rootFolder.CreateDocumentSet(folderName, devisCT.Id);

我现在从要创建文档集的库中获取内容类型。

检索到的 ContentTypeId 更长,并且此 ID 有效。

您会注意到我使用了 GetContentTypeByName 方法,它与 GetContentTypeByID 一样有效。

于 2016-11-16T12:29:17.737 回答
1

实际上,至少我目前在Microsoft.SharePoint.Client.UnknownError尝试通过SharePoint Online中的 CSOM API 创建文档集时遇到了同样的问题(异常) 。

如何重现?

Microsoft.SharePointOnline.CSOM通过库创建文档集时:

var list = ctx.Web.Lists.GetByTitle("Documents");

var docSetContentType = ctx.Site.RootWeb.ContentTypes.GetById("0x0120D520");
ctx.Load(docSetContentType);

ctx.Load(list.RootFolder);
ctx.ExecuteQuery();
var result = DocumentSet.Create(ctx, list.RootFolder, docSetName, docSetContentType.Id);
ctx.ExecuteQuery();

例外情况Microsoft.SharePoint.Client.UnknownError发生在SharePoint Online中。

Microsoft.SharePointOnline.CSOM注意:在最新和以前版本的库中已检测到该错误。这让我认为它与 CSOM 库无关,而是与 SharePoint Online CSOM 服务本身有关。

解决方法

但是有一种解决方法可以创建一个文档集(不Microsoft.SharePoint.Client.DocumentSet涉及命名空间)

public static void CreateDocumentSet(List list, string docSetName)
{
        var ctx = list.Context;
        if (!list.IsObjectPropertyInstantiated("RootFolder"))
        {
            ctx.Load(list.RootFolder);
            ctx.ExecuteQuery();
        }

        var itemInfo = new ListItemCreationInformation();
        itemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
        itemInfo.LeafName = docSetName;
        itemInfo.FolderUrl = list.RootFolder.ServerRelativeUrl;
        var item = list.AddItem(itemInfo);
        item["ContentTypeId"] = "0x0120D520";
        item["HTML_x0020_File_x0020_Type"] = "SharePoint.DocumentSet";
        item.Update();
        ctx.ExecuteQuery();
}

已针对 SharePoint2010和版本2013进行了验证Online

用法

var list = ctx.Web.Lists.GetByTitle("Documents");
CreateDocumentSet(list,docSetName);
于 2016-11-16T12:17:17.027 回答