1

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"));
clientContext.ExecuteQuery();

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";

    newListItem.Update();
    list.Update();
    clientContext.ExecuteQuery();
}

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

2
  • 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 Feb 6, 2019 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, 2019 at 13:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.