Introduction

In this blog, I would like to explain how to create Document Set in Document Library, using CSOM. A Document Set is a group of related documents, which can be created in one step and then managed as a single entity.

Activate Document Set Feature

We need to activate it before you can create or configure new Document Set content types.

  • Go to the top-level site in the site collection for which you want to enable Document Sets.
  • Site Actions menu--> click Site Settings.
  • Site Collection Administration - Site collection features.
  • Find Document Sets in the list and then click Activate.

Add Document Set as a Content Type to your Document Library

  • Go to Document Settings and change the Advanced Settings to Allow management of content types.



  • Go to the Settings- add from existing site content types and find the Document Set content type. Select Document Set and click Add.


  • Go to your Document library and select New Document -> Document Set from the drop-down list.


Here, we will see how to create a Document Set programmatically, using csom.

Source Code

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Microsoft.SharePoint.Client;
  7. using Microsoft.SharePoint.Client.DocumentSet;
  8. namespace DocumentSet
  9. {
  10. class Program {
  11. static void Main(string[] args) {
  12. string siteURL = "https://gowtham.sharepoint.com";
  13. ClientContext clientContext = new ClientContext(siteURL);
  14. List list = clientContext.Web.Lists.GetByTitle("TestLibrary1");
  15. clientContext(list.RootFolder);
  16. clientContext.ExecuteQuery();
  17. var itemInfo = new ListItemCreationInformation();
  18. itemInfo.UnderlyingObjectType = FileSystemObjectType.Folder;
  19. itemInfo.LeafName = docSetName;
  20. itemInfo.FolderUrl = list.RootFolder.ServerRelativeUrl;
  21. var item = list.AddItem(itemInfo);
  22. item["ContentTypeId"] = "0x0120D520";
  23. item["HTML_x0020_File_x0020_Type"] = "SharePoint.DocumentSet";
  24. item.Update();
  25. clientContext.ExecuteQuery();
  26. }
  27. }
  28. }
Copy the code, shown above, paste it in Visual Studio and run. Document Set created successfully.