SPDocTemplateCollection.Item Property
Gets the document template object at the specified index in the collection. In C#, this property is the indexer for the SPDocTemplateCollection class.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public ReadOnly Property Item ( _
iIndex As Integer _
) As SPDocTemplate
Get
'Usage
Dim instance As SPDocTemplateCollection
Dim iIndex As Integer
Dim value As SPDocTemplate
value = instance.Item(iIndex)
public SPDocTemplate this[
int iIndex
] { get; }
Parameters
iIndex
Type: System.Int32A 32-bit integer that specifies the index.
Property Value
Type: Microsoft.SharePoint.SPDocTemplate
A SPDocTemplate object that represents the document template.
Remarks
The Item property throws an ArgumentOutOfRangeException if the specified index is outside the valid range of indexes for the collection.
Examples
The following code example iterates through all the sites on a server and uses the indexer to display the site name, the name of each document template, and the template type for every document template.
The example assumes the existence of an .aspx page that contains a label control.
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 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
Label1.Text += SPEncode.HtmlEncode(site.Name) & " :: " _
& SPEncode.HtmlEncode(docTemps(i).Name) & " :: "
& docTemps(i).Type & "<BR>"
Next i
Next site
SPSite oSiteCollection = SPContext.Current.Site;
SPWebCollection collWebsites = oSiteCollection.AllWebs;
foreach (SPWeb oWebsite in collWebsites)
{
SPDocTemplateCollection collDocTemplates = oWebsite.DocTemplates;
for (int intIndex=0; intIndex<collDocTemplates.Count; intIndex++)
{
Label1.Text += SPEncode.HtmlEncode(oWebsite.Name) + " :: " +
SPEncode.HtmlEncode(collDocTemplates[intIndex].Name) + " :: " +
collDocTemplates[intIndex].Type + "<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.