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

我的未来我决定 提交于 2019-12-05 11:04:16

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;
}

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;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!