Steps
Open Visual Studio in your system.
  1. using System;
  2. using Microsoft.Office.DocumentManagement.DocumentSets;
  3. using Microsoft.SharePoint;
  4. using Microsoft.SharePoint.WebControls;
  5. namespace ManageDocumentSetTemplate
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int count = 0;
  12. string resultLabel="";
  13. //Get the Shared Documents document libary
  14. SPWeb currentWeb = SPContext.Current.Web;
  15. SPDocumentLibrary sharedDocuments = (SPDocumentLibrary)currentWeb.Lists["Shared Documents"];
  16. //Loop though all the folders. Some of them will be document sets
  17. //NOTE: don't use the sharedDocuments.Folders collection! Use sharedDocuments.RootFolder.SubFolders
  18. foreach(SPFolder currentFolder in sharedDocuments.RootFolder.SubFolders)
  19. {
  20. //Get the corresponding document set
  21. DocumentSet currentDocSet = DocumentSet.GetDocumentSet(currentFolder);
  22. //Strangely the previous line always returns a document set object
  23. //Even if the current folder is not a document set. So we use the
  24. //following test to find out if the current folder is a document set
  25. if (currentDocSet.Item != null)
  26. {
  27. //This folder is a document set. Increase the count
  28. count += 1;
  29. //Read some properties of the document set
  30. resultLabel += "Name: " + currentFolder.Name + "<br />";
  31. resultLabel += "Content Type: " + currentDocSet.ContentType.Name + "<br />";
  32. resultLabel += "Document Count: " + currentDocSet.Folder.ItemCount + "<br />";
  33. resultLabel += "Welcome Page: " + currentDocSet.WelcomePageUrl + "<br /><br />";
  34. }
  35. }
  36. //Display the count
  37. Console.WriteLine(count.ToString());
  38. }
  39. }
  40. }
Hit F5 and check the output..
Hope you hve enjoyed my articles.