locked
How to get size of top level sub sites ( not the nested sub sites) in MOSS 2007 RRS feed

  • Question

  • How to get size of top level sub sites ( not the nested sub sites) only to top level sub sites in MOSS 2007

    Thanks, Ram Ch

    Monday, November 11, 2013 9:03 AM

Answers

  • You can use the following code to get site collection or sub-sites size:

    Get Site Collection Size :

    string siteCollectionURL = ""; // Site Collection URL
    SPSiteAdministration st = new SPSiteAdministration(siteCollectionURL);
    float scDiskUsage = st.DiskUsed;
    float a = (scDiskUsage / (1024 * 1024));

    Get sub-sites size:

    string siteCollectionURL = ""; // Site Collection URL
    SPSite oSPSite = new SPSite(siteCollectionURL);
    SPWeb oSPWeb = oSPSite.RootWeb;
    float totalSiteDiskUsage = GetWebSize(oSPWeb);
    string filePath = @"C:\MyFile.txt"; // File Path
    FileStream sb = new FileStream(filePath, FileMode.Create);
    StreamWriter sw = new StreamWriter(sb);
    sw.Write(str);
    sw.Close();


    private float GetWebSize(SPWeb web)
    {
    float total = 0;

    foreach (SPFolder folder in web.Folders)
    {
    total += GetFolderSize(folder);
    }

    foreach (SPWeb subweb in web.Webs)
    {
    total += GetWebSize(subweb);
    subweb.Dispose();
    }
    if (!web.IsRootWeb)
    {
    str += "Site url : " + web.Url + "\r\n"; ;
    str += "Size : " + (total/(1024*1024)) + " MB" + "\r\n";
    str += "\r\n";
    }
    return total;
    }

    private float GetFolderSize(SPFolder folder)
    {
    float folderSize = 0;

    foreach (SPFile file in folder.Files)
    {
    folderSize += file.Length;
    }

    foreach (SPFolder subfolder in folder.SubFolders)
    {
    folderSize += GetFolderSize(subfolder);
    }

    return folderSize;
    }

    In addition, you can use stsadm.exe tool to get site size, for detailed information, please refer to the following article:

    http://social.technet.microsoft.com/Forums/en-US/sharepointgeneral/thread/a2e84703-2be2-488d-84f5-d6f287de621d
    http://office.microsoft.com/en-us/sharepointdesigner/HA101741361033.aspx

    Also,
    Download the code from http://www.15seconds.com/issue/050623.htm (however it is form SPS 2003, but ut will work in MOSS also)

    You can find the storage used data in the Site Collection Usage Summary. This option can be enabled if you enable the Usage Analysis Processing option in the Central Administration site. Once this option is enabled if you navigate to the Site Actions Menu -> Modify All Site Settings, in the Site Collection Administration tab you can find the Usage Summary, clicking which will display the Site Collection Usage Summary.

    Other than this see http://office.microsoft.com/en-us/sharepointdesigner/HA101741361033.aspx



    Hope this helps.

    Regards,

    Jayant

    *Please remember to mark your question as answered & Vote helpful,if this solves/helps your problem.* 

                    

    jayant prabhakar

    Monday, November 11, 2013 9:33 AM

All replies

  • I don't think there is direct method to achieve this.  - prithvi
    Monday, November 11, 2013 9:20 AM
  • You can use the following code to get site collection or sub-sites size:

    Get Site Collection Size :

    string siteCollectionURL = ""; // Site Collection URL
    SPSiteAdministration st = new SPSiteAdministration(siteCollectionURL);
    float scDiskUsage = st.DiskUsed;
    float a = (scDiskUsage / (1024 * 1024));

    Get sub-sites size:

    string siteCollectionURL = ""; // Site Collection URL
    SPSite oSPSite = new SPSite(siteCollectionURL);
    SPWeb oSPWeb = oSPSite.RootWeb;
    float totalSiteDiskUsage = GetWebSize(oSPWeb);
    string filePath = @"C:\MyFile.txt"; // File Path
    FileStream sb = new FileStream(filePath, FileMode.Create);
    StreamWriter sw = new StreamWriter(sb);
    sw.Write(str);
    sw.Close();


    private float GetWebSize(SPWeb web)
    {
    float total = 0;

    foreach (SPFolder folder in web.Folders)
    {
    total += GetFolderSize(folder);
    }

    foreach (SPWeb subweb in web.Webs)
    {
    total += GetWebSize(subweb);
    subweb.Dispose();
    }
    if (!web.IsRootWeb)
    {
    str += "Site url : " + web.Url + "\r\n"; ;
    str += "Size : " + (total/(1024*1024)) + " MB" + "\r\n";
    str += "\r\n";
    }
    return total;
    }

    private float GetFolderSize(SPFolder folder)
    {
    float folderSize = 0;

    foreach (SPFile file in folder.Files)
    {
    folderSize += file.Length;
    }

    foreach (SPFolder subfolder in folder.SubFolders)
    {
    folderSize += GetFolderSize(subfolder);
    }

    return folderSize;
    }

    In addition, you can use stsadm.exe tool to get site size, for detailed information, please refer to the following article:

    http://social.technet.microsoft.com/Forums/en-US/sharepointgeneral/thread/a2e84703-2be2-488d-84f5-d6f287de621d
    http://office.microsoft.com/en-us/sharepointdesigner/HA101741361033.aspx

    Also,
    Download the code from http://www.15seconds.com/issue/050623.htm (however it is form SPS 2003, but ut will work in MOSS also)

    You can find the storage used data in the Site Collection Usage Summary. This option can be enabled if you enable the Usage Analysis Processing option in the Central Administration site. Once this option is enabled if you navigate to the Site Actions Menu -> Modify All Site Settings, in the Site Collection Administration tab you can find the Usage Summary, clicking which will display the Site Collection Usage Summary.

    Other than this see http://office.microsoft.com/en-us/sharepointdesigner/HA101741361033.aspx



    Hope this helps.

    Regards,

    Jayant

    *Please remember to mark your question as answered & Vote helpful,if this solves/helps your problem.* 

                    

    jayant prabhakar

    Monday, November 11, 2013 9:33 AM