none
How to get programmatically the size of a spweb or spsite?

    Question

  • Hi,

    is it possible to get the size of an SPWeb or SPSite programmatically?

    thank you
    yavuz
    Monday, September 07, 2009 6:28 PM

Answers

All replies

  • Hi Yavuz,

    There is a Sharepoint method which provides information about storage space location:SPSite.StorageManagementInformation.

    Try the below links:

    http://phxlog.blogspot.com/

    http://www.codeplex.com/SPSiteStorageInfo

    Thanks,
    Veera Reddy
    • Marked as answer by Yavuz Bogazci Monday, September 07, 2009 8:15 PM
    Monday, September 07, 2009 7:48 PM
  • You can also use following code

     

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

    Monday, September 07, 2009 9:13 PM