Share via


SPFolder Class

The SPFolder class represents a folder on a SharePoint Web site.

System.Object

   Microsoft.SharePoint.SPFolder

Public Methods

The following table shows the public methods of the SPFolder class and a brief description of each.

Name Description
CopyTo Copies the folder and its contents into a new folder at the specified URL.
MoveTo Moves the folder to the specified URL.
ToString Returns the relative URL of the folder based on the parent Web site.

Public Properties

The following table shows the public properties of the SPFolder class, the data type of each property, and a brief description of each.

Name Data Type Description
ContainingDocumentLibrary System.Guid Gets the document library that contains the folder.
Exists Boolean Gets a Boolean value that indicates whether the folder exists.
Files Microsoft.SharePoint.SPFileCollection Gets the collection of all files contained in the folder.
Name String Gets the name of the folder.
ParentFolder Microsoft.SharePoint.SPFolder Gets the parent folder of the folder.
ParentWeb Microsoft.SharePoint.SPWeb Gets the parent Web site of the folder.
ServerRelativeUrl String Gets the server-relative URL of the folder.
SubFolders Microsoft.SharePoint.SPFolderCollection Gets the collection of subfolders contained within the folder.
Url String Gets the site-relative URL of the folder.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Remarks

Various folder properties exist in the Microsoft.SharePoint namespace that return a folder object, but the GetFolder method of the SPWeb class returns any folder from within a site or subsite.

Use the Folders property of the SPWeb class, or the Subfolders property of the SPFolder class, to return an SPFolderCollection object that represents the collection of folders for a site or folder. Use an indexer to return a single folder from the collection. For example, if the collection is assigned to a variable named myFolders, use myFolders[index] in C#, or myFolders(index) in Visual Basic .NET, where index is either the index number of the folder in the collection or the display name of the folder.

Example

The following code example displays information about the folders in a site and all its subsites, including the site name, folder name, number of files in the folder, and total size of the files.

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

The example assumes the existence of a .aspx page that contains a label control.

Requirements

Namespace: Microsoft.SharePoint

Platforms: Microsoft Windows Server 2003

Assembly: Windows SharePoint Services (in Microsoft.SharePoint.dll)

Security: Code Access Security