How to create Document Set using CSOM in SharePoint 2013

By Vijai Anand Jun 28, 2013
In this blog you will see how to create Document Set using CSOM in SharePoint 2013
A Document Set is a group of related documents that can be created in one step and then managed as a single entity. Please refer http://office.microsoft.com/en-in/sharepoint-server-help/introduction-to-document-sets-HA101782466.aspx?CTT=5&origin=HA101782461 to understand more about Document Set. Here you will see how to create Document Set using CSOM in SharePoint 2013

Namespaces:
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.DocumentSet;
Assemblies:
Microsoft.SharePoint.Client.dll;
Microsoft.SharePoint.Client.RunTime.dll;
Microsoft.SharePoint.Client.DocumentManagement.dll;
Code Snippet:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.DocumentSet;

namespace CSOMSamples
{
class Program
{
static void Main(string[] args)
{
//// String Variable to store the siteURL
string siteURL = "http://c4968397007/";

//// String Variable to store the document set name
string dsName = "Vijai Documents";

//// Get the context for the SharePoint Site to access the data
ClientContext clientContext = new ClientContext(siteURL);

//// Get the document library in which the document set has to be created
List list = clientContext.Web.Lists.GetByTitle("Documents");

//// Get the parent folder where the document set has to be created
Folder parentFolder = list.RootFolder;

//// Get the "Document Set" content type by id (Document Set content type Id : 0x0120D520) for the document library
ContentType ct = clientContext.Web.ContentTypes.GetById("0x0120D520");
clientContext.Load(ct);
clientContext.ExecuteQuery();

//// Create a new document set
//// A new document set will be created in "Documents" library as "Vijai Documents" under which you can add the documents
DocumentSet.Create(clientContext, parentFolder, dsName, ct.Id);
clientContext.ExecuteQuery();
}
}
}


Vijai Anand

Vijai Anand has been working in IT industry for over 5 years. He holds Bachelor's degree in Electronics and Communication Engineering. Vijai write articles and blogs related to SharePoint 2013, SharePoint 2010, Silv... Read more

COMMENT USING

PREMIUM SPONSORS

Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.

Latest Blogs