You can use the
GetFolder method of the
SPWeb class to return a specified folder. Then you can access individual files in the folder. After instantiating an
SPWeb object (for example, as
oWebsite), use
SPFolder oFolder = oWebsite.GetFolder("Shared Documents") (in Microsoft Visual Basic, use
Dim oFolder As SPFolder = oWebsite.GetFolder("Shared Documents")) to return the Shared Documents folder for the site.
using (SPWeb oWebsite = new SPSite("http://Server/sites/SiteCollection").OpenWeb())
{
string folderUrl = "/Shared Documents/MySubFolder";
SPFolder oFolder = oWebsite.GetFolder(folderUrl);
SPFileCollection collFile = oFolder.Files;
foreach (SPFile oFile in collFile)
{
Label1.Text += "<BR>Url: " + oFile.Url.ToString() + " Size: " + oFile.Length.ToString();
}
}