I have a requirement to programmatically create a document set in a library.

I've done this successfully using the code below, however when I open the document set I see the yellow bar message 'Content types that are available to this Document Set have been added or removed'.

I have tried to set the docset_LastRefresh property as suggested here but this results in the message 'Column "docset_LastRefresh" does not exist. It may have been deleted by another user.'

NetworkCredential creds = new NetworkCredential(ConfigurationManager.AppSettings["SPUsername"], ConfigurationManager.AppSettings["SPPassword"], ConfigurationManager.AppSettings["SPSiteURL"]);
ClientContext clientContext = new ClientContext(ConfigurationManager.AppSettings["SPSiteURL"]);
clientContext.Credentials = CredentialCache.DefaultNetworkCredentials;

List list = clientContext.Web.Lists.GetByTitle("Test Library");
ContentTypeCollection listContentTypes = list.ContentTypes;

clientContext.Load(listContentTypes, types => types.Include(type => type.Id, type => type.Name, type => type.Parent));
var result = clientContext.LoadQuery(listContentTypes.Where(c => c.Name == "Document Set"));

if (result != null)
    ContentType targetDocumentSetContentType = result.FirstOrDefault();
    ListItemCreationInformation newItemInfo = new ListItemCreationInformation();
    newItemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
    newItemInfo.LeafName = "Test document set";

    ListItem newListItem = list.AddItem(newItemInfo);
    newListItem["ContentTypeId"] = targetDocumentSetContentType.Id.ToString();
    newListItem["HTML_x0020_File_x0020_Type"] = "SharePoint.DocumentSet";
    newListItem["DocumentSetDescription"] = "Document set created programatically";


Looking for some advice on how to programmatically provision the document set as part of the creation procedure using CSOM.

  • the provisioning code looks ok. perhaps you might want to check the document set details in library settings > [doc set content type] > doc set settings. maybe you're missing something. also might be worth it trying to create a document set from the user interface and checking if the same happens. you might have a corrupt or misconfigured content type or document library – Tiago Duarte Feb 6 at 11:53
  • Thanks for your suggestions Tiago. I created the same document set using the UI and it is created without the yellow bar. Also tried this in a fresh library and found the same results. – Stuart C Feb 6 at 13:12

Your Answer

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

Browse other questions tagged or ask your own question.