I was looking through some old code I wrote for customers and found this code again. It is used for determining the size of a SPWeb object based on its files. The methods are recursively through all SPWeb, SPFolder and SPFile objects. The result is the size of the SPWeb in number of bytes.
private long GetWebSize(SPWeb web)
{
long total = 0;
foreach (SPFolder folder in web.Folders)
{
total += GetFolderSize(folder);
}
foreach (SPWeb subweb in web.Webs)
{
total += GetWebSize(subweb);
subweb.Dispose();
}
return total;
}
private long GetFolderSize(SPFolder folder)
{
long folderSize = 0;
foreach (SPFile file in folder.Files)
{
folderSize += file.Length;
}
foreach (SPFolder subfolder in folder.SubFolders)
{
folderSize += GetFolderSize(subfolder);
}
return folderSize;
}
I have seen in the past that some people even write methods to access the content databases of SharePoint itself. But keep in mind that Microsoft will not garantee that these content databases stay the same between Service Packs en versions of SharePoint. Neither will they provide help in any way when code like that is found in projects. So keep it to the API functionality which is available to us.