SPFolder Class

Represents a folder on a SharePoint Web site.

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 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.

SPWeb.Folders à return a SPFolderCollection object, then use index to return a single folder
SPFolder.SubFolders à return a SPFolderCollection object, then use index to return a single folder

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 for the Microsoft.SharePoint and Microsoft.SharePoint.Utilities namespaces.

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

SPSite oSiteCollection = SPContext.Current.Site;

SPWebCollection collWebsites = oSiteCollection.AllWebs;

foreach (SPWeb oWebsite in collWebsites)


SPFolderCollection collFolders = oWebsite.Folders;


foreach (SPFolder oFolder in collFolders)


SPFileCollection collFiles = oFolder.Files;


long lngTotalFileSize = 0;


for (int intIndex = 0; intIndex < collFiles.Count; intIndex++)


lngTotalFileSize += collFiles[intIndex].Length;



Label1.Text += ” Web: “ +


+ ” Folder: “ +

SPEncode.HtmlEncode(oFolder.Name) + ” Number: “

+ oFolder.Files.Count +

” Size: “ + lngTotalFileSize + “<BR>”;





Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: