SPFileCollection.Item Property (Int32)
Gets the file object at the specified index in the collection. In Microsoft Visual C#, this property is an indexer for the SPFileCollection 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 SPFile
Get
'Usage
Dim instance As SPFileCollection
Dim iIndex As Integer
Dim value As SPFile
value = instance.Item(iIndex)
public SPFile this[
int iIndex
] { get; }
Parameters
iIndex
Type: System.Int32A 32-bit integer that specifies the index of the file.
Property Value
Type: Microsoft.SharePoint.SPFile
An SPFile object that represents the file.
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 uses the indexer to display the name and author of every file in a Shared Documents document library.
This example requires using directives (Imports in Visual Basic) for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.
The example assumes the existence of an .aspx page that contains a label control.
Dim webSite As SPWeb = SPContext.Current.Web
Try
Dim files As SPFileCollection = webSite.GetFolder("Shared Documents").Files
Dim i As Integer
For i = 0 To files.Count - 1
Label1.Text += SPEncode.HtmlEncode(files(i).Name) + " :: " + files(i).Author.LoginName + "<BR>"
Next i
Finally
webSite.Dispose()
End Try
SPWeb oWebsite = SPContext.Current.Web;
SPFileCollection collFiles = oWebsite.GetFolder("Shared Documents").Files;
for (int intIndex=0; intIndex<collFiles.Count; intIndex++)
{
Label1.Text += SPEncode.HtmlEncode(collFiles[intIndex].Name) +
" :: " + collFiles[intIndex].Author.LoginName + "<BR>";
}