Programatically creating document sets in SharePoint 2010


You can create a document set using sharePoint object model, SharePoint Client OM and also using SharePoint 2010 web services.
This example shows how to create document sets using SharePoint object model.
public static void CreateDocumentSetContentType(string libraryUrl)
{
using (SPSite site = new SPSite(libraryUrl))
{
using (SPWeb web = site.OpenWeb())
{
//create the new document set contenttype
SPContentType newDocumentSet = web.ContentTypes.Add (new SPContentType(web.ContentTypes["Document Set"],web.ContentTypes,
“MydocumentSet”));
//get a an instance of DocumentSetTemplate for the new document set
DocumentSetTemplate newDocumentSetTemplate = DocumentSetTemplate.GetDocumentSetTemplate(newDocumentSet );
//add allowable content types
newDocumentSetTemplate.AllowedContentTypes.Add
(web.ContentTypes["Document"].Id);
//add a shareable property
newDocumentSetTemplate.SharedFields.Add(newDocumentSetContentType.Fields["Module"]);
newDocumentSetTemplate.Update(true);
newDocumentSet .Update();
web.Update();
}
}
}

Popular posts from this blog

Register Event Handlers plus free Site Settings – Manage Event Handlers Add-on solution

Custom Form Base Login Web Part With Sharepoint 2010

Real World Branding with SharePoint 2010 Publishing Sites