I got a frustrating problem: When I create a document set via Client Object Model, the document set is created as intended as far as it concerns the appearance outside the treeview. It's shown as document set with all its properties including being redirected to the document set's homepage. But, in the treeview, it is listed. Manually created document sets are not listed there, and I cannot figure out why the client object model document set is listed there. Furthermore, clicking the treeview item, it opens the document set as a folder. No document set homepage there.
Has someone got an idea?
Web web = clientContext.Web;
ContentTypeCollection listContentTypes = existingList.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 == "mydocsetname"));
clientContext.ExecuteQuery();
ContentType targetDocumentSetContentType = result.FirstOrDefault();
ListItemCreationInformation newItemInfo = new ListItemCreationInformation();
newItemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
newItemInfo.LeafName = documentSetName;
newItemInfo.FolderUrl = rootFolderUrl.ToString() + dir;
ListItem newListItem = existingList.AddItem(newItemInfo);
newListItem["ContentTypeId"] = targetDocumentSetContentType.Id.ToString();
newListItem.Update();
existingList.Update();
clientContext.ExecuteQuery();