Share via


SPFolderCollection.Item property (Int32)

Gets the folder object at the specified index in the collection. In C#, this property is an indexer for the SPFolderCollection class.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public ReadOnly Default Property Item ( _
    iIndex As Integer _
) As SPFolder
    Get
'Usage
Dim instance As SPFolderCollection
Dim iIndex As Integer
Dim value As SPFolder

value = instance(iIndex)
public SPFolder this[
    int iIndex
] { get; }

Parameters

  • iIndex
    Type: System.Int32

    A 32-bit integer that specifies the index of the folder.

Property value

Type: Microsoft.SharePoint.SPFolder
An SPFolder object that represents the folder.

Remarks

The Item property throws an ArgumentOutOfRangeException if the specified index is outside the valid range of indices for the collection.

Examples

The following code example uses the indexer to display the name and number of files for each folder in a site.

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

Dim site As SPWeb = SPControl.GetContextWeb(Context)
Dim folders As SPFolderCollection = site.Folders
Dim i As Integer

For i = 0 To folders.Count - 1

    Label1.Text += SPEncode.HtmlEncode(folders(i).Name) & " :: " & 
        folders(i).Files.Count.ToString() & "<BR>"

Next i 
SPWeb oWebsite = SPContext.Current.Web;
SPFolderCollection collFolders= oWebsite.Folders;

for (int intIndex=0; intIndex<collFolders.Count; intIndex++)
{
    Label1.Text += SPEncode.HtmlEncode(collFolders[intIndex].Name) 
        + " -- " + 
        collFolders[intIndex].Files.Count.ToString() + "<BR>";
}

See also

Reference

SPFolderCollection class

SPFolderCollection members

Item overload

Microsoft.SharePoint namespace