DocumentSetTemplate Class

Represents the template on which DocumentSet objects are based.


Namespace:  Microsoft.Office.DocumentManagement.DocumentSets
Assembly:  Microsoft.Office.DocumentManagement (in Microsoft.Office.DocumentManagement.dll)

public class DocumentSetTemplate

There is one template for each document set content type and one template for every other content type that inherits from it. Templates describe properties of the document set content type. These properties include the content types allowed inside the document set, its default documents, its shared fields, the fields that are displayed in its welcome page, and the view to use for the welcome page.

using System;
using Microsoft.SharePoint;
using Microsoft.Office.DocumentManagement.DocumentSets;

namespace SyncAllDocsetTemplates
class Program
static void Main(string[] args)
//Sets a field as shared and adds an allowed content type
//to all document set content types, the field that is now
//shared will be displayed on the welcome page
//and all of the default documents will be made to have the
//newly allowed content type
using (SPSite site = new SPSite("http://localhost")) //get the site
using (SPWeb web = site.RootWeb)  //get the web
SPField field = web.Fields["ExistingField"];//get the new field
SPContentType contentType = web.ContentTypes["ExistingCT"];//get the new content type
foreach (SPContentType ct in web.ContentTypes)//iterate through all content types
if (DocumentSetTemplate.Id.IsParentOf(ct.Id) || ct.Id == DocumentSetTemplate.Id)//only take action if it's the base document set content type or one of its childs
//Get the document set template
DocumentSetTemplate docsetTemplate = DocumentSetTemplate.GetDocumentSetTemplate(ct);
//Add the new content type, make the field shared, and add it to the welcomepage
//Change the content type of all default documents to the new content type
foreach (DefaultDocument defDoc in docsetTemplate.DefaultDocuments)
docsetTemplate.DefaultDocuments.ChangeContentTypeForDocument(defDoc.Name, contentType.Id);
//Finally, save the changes

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.