I am trying to create a document set through the CSOM API and my solution was working for several days and then suddenly stopped working. None of my code changed, and the admin of the sharepoint server I am communicating with insists that nothing has changed there either. The line that fails is the "DocumentSet.Create" call. Code below (I've omitted my error checking and exception handling for clarity/brevity):

// Retrieving parent folder where I also ensure it's not null
Folder parentFolder = GetParentFolder(context);

var contentType = context.Web.ContentTypes.FirstOrDefault( ct => ct.Name == "Some document type");
var response = DocumentSet.Create( context, parentFolder, "Deal #1, contentType.Id );

The response is always empty/null, and when I capture the exception that gets thrown it simply says "Unknown error". Again, this solution went from working to not-working without any code changes.

Is there anything that could have changed on the Sharepoint Server that could have caused this? I can still perform other operations (reading/writing/deleting documents), so I'm confident my "context" isn't the problem.

  • I noticed the same problem yesterday. My solution that worked for months just stopped working yesterday. I spent several hours trying to figure out what went wrong. No answer either
    – Ayona
    Nov 12 '16 at 9:56
  • From yesterday, I have same error using Javascript script Error Message: 'Unknown Error' Nov 15 '16 at 8:38
  • Glad I'm not the only one getting this mysterious error. Please let me know if either of you guys figure out a solution/cause. I suspect there's something going on with the credentials, working to verify if that's the case or not.
    – Jeremy
    Nov 15 '16 at 21:16
  • Are you on SharePoint Online? I've received reports that our document sets are no longer being created as well. I wonder if an update was pushed out that broke the current process.
    – wjervis
    Nov 16 '16 at 13:04

SOLVED! Interesting that others are having this issue as well. My code stopped working yesterday 11/14/2016 around 5pm EST, was working perfectly fine for months until then. Anyways here's the solution based on some help from @Karthik 's response

My code is very similar and fails with "unknown error" on the 3rd line:

ContentType ct = currentWeb.ContentTypes.GetById("0x0120D520");
DocumentSet.Create(currentWeb.Context, parentFolder, "test 123", ct.Id);

Solution was 2 changes, 1) change to the longer content type & 2) change to the list content type vs. the sites. Basically look at line 6 below, keep in mind your content type ID may be different then mine.

Web web = clientContext.Web; 
List currentList = web.Lists.GetByTitle("ListName"); 
ContentType ct = currentList.ContentTypes.GetById("0x0120D5200066C2CD25A0472649B59FBAEAA85A068B");
DocumentSet.Create(currentWeb.Context, parentFolder, "test 123", ct.Id);

Hope it helps!

  • Hi Chris, thank you for the help. I'm trying to implement your fix but I'm not sure how you're getting the "currentList" object. Would you please explain?
    – Jeremy
    Nov 15 '16 at 23:04
  • Sure - here's the code for current list
    – Chris
    Nov 15 '16 at 23:15
  • Web web = clientContext.Web; clientContext.Load(web); List currentList = web.Lists.GetByTitle("ListName"); clientContext.Load(currentList); clientContext.ExecuteQuery();
    – Chris
    Nov 15 '16 at 23:16
  • sorry for the format, I hope it helps.
    – Chris
    Nov 15 '16 at 23:17
  • 1
    @Chris, I moved the code from your comments into the answer. In the future, you can click the edit link under your answer and do this yourself.
    – wjervis
    Nov 16 '16 at 13:03

There might be a permission issue. I was getting the same error. In my case the document library had unique permissions and the credentials under which the client context was created didn't have permission in the document library.

I think you should check permission of user who is creating the client context in the document library.

Edit: I have checked you code and it seems that it is failing for Site Content Type. I have tried using List content type and that Unknown exception stopped occurring.

Try again by replacing the site content type id with your list content type id . (hint: The list content type id will be a bit longer)

for example:

ContentType ct = clientContext.Web.ContentTypes.GetById("0x0120D52000B0841A02FF9B3E41A48AFF0422E7AF56000FE5787B5FG2504C95EE7EE17200FB16");
var doxSet = DocumentSet.Create(clientContext, folder, "9999", ct.Id);
  • Thanks for the reply. I am still able to read and write files to document sets that already exist, it's just I cannot create document sets. Would I still be able to write/read files if it was a permissions issue?
    – Jeremy
    Nov 14 '16 at 19:27
  • It may be you have only update permission. To create doc set you need "Add Permission". Nov 15 '16 at 7:06
  • Thank you for the replies. Karthik, I tried your approach and it seems to yield the same results as before. The "Create" still fails. Monica, if it was the case that I only had "update permission", would I still be able to write files to sharepoint? Because I'm still able to do that.
    – Jeremy
    Nov 15 '16 at 21:13

thanks a lot. The solution works for me too.

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

The creation of the documentset stop working suddenly

I use a provider hosted Add-in with CSOM and a AppOnly Access Token for the clientContext with this 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.