SharePoint Gen

The official blog of Chandrasekar, Microsoft SharePoint PFE

How BIG is your SharePoint

How BIG is your SharePoint

  • Comments 1

Size of Site collection:

string siteCollectionURL = “http://localhost:80/sites/TestSite”;
SPSiteAdministration oSPSiteAdministration = new SPSiteAdministration(siteCollectionURL);
float scDiskUsage = oSPSiteAdministration.DiskUsed;
float sizeOfSiteCollection = (scDiskUsage / (1024 * 1024));  // In MB
 

 

Total size of sub-sites in Site collection :

string siteCollectionURL = “http://localhost:80/sites/TestSite”;
SPSite oSPSite = new SPSite(siteCollectionURL);
SPWeb oSPWeb = oSPSite.RootWeb;
float totalSubSitesUsage = GetWebSize(oSPWeb);
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();
  }
  return (total/(1024*1024));
}
 
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;
}

Leave a Comment
  • Please add 5 and 7 and type the answer here:
  • Post