DocumentSetTemplate class
Represents the template on which DocumentSet objects are based.
Inheritance hierarchy
System.Object
Microsoft.Office.DocumentManagement.DocumentSets.DocumentSetTemplate
Namespace: Microsoft.Office.DocumentManagement.DocumentSets
Assembly: Microsoft.Office.DocumentManagement (in Microsoft.Office.DocumentManagement.dll)
Syntax
'Declaration
Public Class DocumentSetTemplate
'Usage
Dim instance As DocumentSetTemplate
public class DocumentSetTemplate
Remarks
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.
Examples
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("https://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
docsetTemplate.AllowedContentTypes.Add(contentType.Id);
docsetTemplate.SharedFields.Add(field);
docsetTemplate.WelcomePageFields.Add(field);
//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
docsetTemplate.Update(false);
}
}
}
}
}
}
}
Thread safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.