Prasad Bolla's SharePoint Blog

Click Here to go through the Interesting posts within my Blog.

Click Here to go through the new posts in my blog.

Friday, December 02, 2011

Programmatically 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();
}
}
}

No comments:

Post a Comment