SharePoint, how do you programatically determine the storage size of a SPWeb?
Asked Answered
B

2

5

Not of the site collection itself, but the individual SPWeb's.

Bewilder answered 14/10, 2008 at 14:24 Comment(0)
P
7

You should take a look at this blog entry by Alexander Meijers : Size of SPWeb based on its Folders and Files

It provides a clever way of finding the size of an SPWeb or SPFolder by iterating through his content.

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;
}
Parliamentary answered 14/10, 2008 at 14:30 Comment(1)
The article doesn't exist anymore and the code is missing GetFolderSize. There is a discussion with that code here: social.msdn.microsoft.com/forums/en-us/sharepointdevelopment/…Amy
M
0

For anyone who comes back to this question, here is the missing method:

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;
}
Marcelo answered 1/7, 2014 at 18:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.