다음을 통해 공유


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)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public ReadOnly Property Item ( _
    urlOfFolder As String _
) As SPFolder
    Get
'Usage
Dim instance As SPFolderCollection
Dim urlOfFolder As String
Dim value As SPFolder

value = instance.Item(urlOfFolder)
public SPFolder this[
    string urlOfFolder
] { get; }

Parameters

  • urlOfFolder
    Type: System.String

    A 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>";
}

See Also

Reference

SPFolderCollection Class

SPFolderCollection Members

Item Overload

Microsoft.SharePoint Namespace