Tribaud
Tribaud

Reputation: 41

Sharepoint Online Can't create DocumentSet with CSOM Microsoft.SharePoint.Client.DocumentManagement.dll

I am using the OfficeDev.Core to create DocumentSet "Folder" in sharepoint Online in a Provider Hosted Add-in in C#.

I am using the lastest CSOM C# library for Sharepoint On line : Microsoft.SharePoint.Client.dll V16.1.5813.1200 Microsoft.SharePoint.Client.DocumentManagement.dll V16.1.5813.1200

This was working fine for months and yesterday we notice that the method Create from the class  Microsoft.SharePoint.Client.DocumentSet.DocumentSet return an error unknown !

I use a AppOnly Access Token with highest permissions.

Do you have any ideas or workarounds to create a documentset with CSOM ?

Thanks

PS: I try to create this documentset with the UI and it works fine.  

Upvotes: 2

Views: 2158

Answers (2)

Tribaud
Tribaud

Reputation: 41

I find a solution on this post:

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

I experienced the same issue on my tenant on monday morning 14/11/2016

The creation of the documentset stop working suddenly

The existing code :

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

and solution that works for me is :

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

I now take the content type from the Library where I want to create the documentset.

The ContentTypeId retrieved is longuer and this ID works.

You can notice that I use the method GetContentTypeByName and it works as well as the GetContentTypeByID.

Upvotes: 1

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59358

Indeed, at least i'm experiencing at the moment the same issue (Microsoft.SharePoint.Client.UnknownError exception) while trying to create a document set via CSOM API in SharePoint Online.

How to reproduce?

While creating a document set via Microsoft.SharePointOnline.CSOM library:

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();

the exception of Microsoft.SharePoint.Client.UnknownError occurs in SharePoint Online.

Note: the error has been detected in the latest and previous versions of Microsoft.SharePointOnline.CSOM library. That makes me think it is not related with CSOM library but rather with SharePoint Online CSOM service itself.

Workaround

But there is a workaround that allows to create a Document Set (without Microsoft.SharePoint.Client.DocumentSet namespace involved)

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();
}

Has been verified against SharePoint 2010, 2013 and Online versions

Usage

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

Upvotes: 2

Related Questions