Monday, October 25, 2010

Programmatically Creating Document sets in sharepoint 2010

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