SPFolderCollection.Item property (String)
Gets the folder object that is located at the specified URL from 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 ( _
urlOfFolder As String _
) As SPFolder
Get
'Usage
Dim instance As SPFolderCollection
Dim urlOfFolder As String
Dim value As SPFolder
value = instance(urlOfFolder)
public SPFolder this[
string urlOfFolder
] { get; }
Parameters
urlOfFolder
Type: System.StringA string that contains the URL.
Property value
Type: Microsoft.SharePoint.SPFolder
An SPFolder object that represents the folder.
Examples
The following code example uses the indexer to display the name and length of each file in the specified folder.
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 folder As SPFolder = site.Folders("Shared Documents")
Dim file As SPFile
For Each file In folder.Files
Label1.Text += folder.Url & " :: " &
SPEncode.HtmlEncode(file.Name) &
" :: " & file.Length.ToString() & "<BR>"
Next file
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>";
}