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.