SharePoint,您如何以编程方式确定SPWeb的存储大小?

时间:2008-10-14 14:24:35

标签: sharepoint spweb

不是网站集本身,而是单个SPWeb的。

2 个答案:

答案 0 :(得分:7)

你应该看一下Alexander Meijers的博客文章:Size of SPWeb based on its Folders and Files

通过迭代他的内容,它提供了一种聪明的方法来查找SPWeb或SPFolder的大小。

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

答案 1 :(得分:0)

对于回到这个问题的人来说,这是缺少的方法:

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