Share via


SPDocTemplateCollection Class

Represents a collection of document templates.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.SPDocTemplateCollection

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<SubsetCallableTypeAttribute> _
Public Class SPDocTemplateCollection _
    Inherits SPBaseCollection
'Usage
Dim instance As SPDocTemplateCollection
[SubsetCallableTypeAttribute]
public class SPDocTemplateCollection : SPBaseCollection

Examples

The following code example collects into an array all document templates of all sites in the current site collection and then iterates through the array elements to display properties of each template.

The example assumes the existence of an .aspx page that contains a label control named Label1.

This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

Dim siteCollection As SPSite = SPControl.GetContextSite(Context)
Dim sites As SPWebCollection = siteCollection.AllWebs
Dim arrDocTemps As New ArrayList()
Dim site As SPWeb

For Each site In  sites

    Dim docTemps As SPDocTemplateCollection = site.DocTemplates
    Dim i As Integer

    For i = 0 To docTemps.Count - 1

        arrDocTemps.Add(docTemps(i))

    Next i

Next site

Dim docTemp As SPDocTemplate

For Each docTemp In  arrDocTemps

    Label1.Text += SPEncode.HtmlEncode(docTemp.Name) & " :: " 
        & docTemp.DefaultTemplate & "<BR>"

Next docTemp 
SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs;
ArrayList arrDocTemplates = new ArrayList();
foreach (SPWeb oWebsite in collWebsites)
{
    SPDocTemplateCollection collDocTemplates = oWebsite.DocTemplates;
    for (int intIndex = 0; intIndex < collDocTemplates.Count; intIndex++)
    {
        arrDocTemplates.Add(collDocTemplates[intIndex]);
    }
                
    foreach (SPDocTemplate oDocTemplate in arrDocTemplates)
    {
        Label1.Text += SPEncode.HtmlEncode(oDocTemplate.Name) + 
            " -- " + oDocTemplate.DefaultTemplate + "<BR>";
    }
    oWebsite.Dispose();
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

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.

See Also

Reference

SPDocTemplateCollection Members

Microsoft.SharePoint Namespace