Steps
Open Visual Studio in your system.
- Select Console Application template and give as name.
- Add a Microsoft.Client Assembly reference file in right side reference tab in visual studio.
- Replace Program.cs with the source code.
- using System;
- using Microsoft.Office.DocumentManagement.DocumentSets;
- using Microsoft.SharePoint;
- using Microsoft.SharePoint.WebControls;
- namespace ManageDocumentSetTemplate
- {
- class Program
- {
- static void Main(string[] args)
- {
- int count = 0;
- string resultLabel="";
- //Get the Shared Documents document libary
- SPWeb currentWeb = SPContext.Current.Web;
- SPDocumentLibrary sharedDocuments = (SPDocumentLibrary)currentWeb.Lists["Shared Documents"];
- //Loop though all the folders. Some of them will be document sets
- //NOTE: don't use the sharedDocuments.Folders collection! Use sharedDocuments.RootFolder.SubFolders
- foreach(SPFolder currentFolder in sharedDocuments.RootFolder.SubFolders)
- {
- //Get the corresponding document set
- DocumentSet currentDocSet = DocumentSet.GetDocumentSet(currentFolder);
- //Strangely the previous line always returns a document set object
- //Even if the current folder is not a document set. So we use the
- //following test to find out if the current folder is a document set
- if (currentDocSet.Item != null)
- {
- //This folder is a document set. Increase the count
- count += 1;
- //Read some properties of the document set
- resultLabel += "Name: " + currentFolder.Name + "<br />";
- resultLabel += "Content Type: " + currentDocSet.ContentType.Name + "<br />";
- resultLabel += "Document Count: " + currentDocSet.Folder.ItemCount + "<br />";
- resultLabel += "Welcome Page: " + currentDocSet.WelcomePageUrl + "<br /><br />";
- }
- }
- //Display the count
- Console.WriteLine(count.ToString());
- }
- }
- }
Hit F5 and check the output..
Hope you hve enjoyed my articles.

Vijay SPosted Jun 17, 2015, 9:11 AM
Good one