Compartilhar via


How BIG is your SharePoint

Size of Site collection:

 string siteCollectionURL = “https://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 = “https://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;
 }

Comments