Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SPFolderCollection class

Represents a collection of SPFolder objects.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
[ClientCallableTypeAttribute(Name = "FolderCollection", ServerTypeId = "{b6b425aa-9e17-4205-a4aa-b82c2c3f884d}", 
	CollectionIndexerMethodClientName = "GetByUrl", CollectionCreateEntityMethodClientName = "Create", 
	CollectionChildItemType = typeof(SPFolder), SampleUrl = "{apiroot}/web/folders")]
[SubsetCallableTypeAttribute]
public class SPFolderCollection : SPBaseCollection

Use the Folders property of the SPWeb class, or the Subfolders() property of the SPFolder class, to return the collection of folders for a site or folder. To create a folder, use the Add method of SPFolderCollection.

Use an indexer to return a single folder from the collection. For example, assuming the collection is assigned to a variable named collFolders, use collFolders[index] in C#, or collFolders(index) in Visual Basic, where index is either the index number of the folder in the collection or the display name of the folder.

The following code example copies all the subfolders of a Shared Documents document library, excluding the Forms subfolder, into another document library on the same site.

SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Site_Name"])
{
    SPFolderCollection collFolders =
        oWebsite.GetFolder("Shared Documents").SubFolders;
    SPFolder oFolderDest = oWebsite.GetFolder("Destination_Folder");

    for (int intIndex = 0; intIndex < collFolders.Count; intIndex++)
    {
        if (collFolders[intIndex].Name != "Forms")
        {
            collFolders[intIndex].CopyTo(oFolderDest.Url + "/" +
                collFolders[intIndex].Name);
        }
    }
}
NoteNote

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.