SiteCollection Storage Information
by Shantha Kumar • November 28, 2011 • SharePoint, SharePoint-2010 • 0 Comments
SharePoint has the Usage Analysis Time job, which updates the following information for the sites,
- Storage,
- Discussion Storage,
- Bandwidth,
- Hits,
- Visits
The SPSite.Usage property gives us the information of site usage, bandwidth, visits.
Here I am adding the snippet for getting the Free Space available against Storage Quota and Space used by Site Collection,
using (SPSite site = new SPSite("http://localhost"))
{
SPSite.UsageInfo susg = site.Usage;
long spaceused = (((susg.Storage + 0x80000L) / 0x100000L));
if (site.Quota.StorageMaximumLevel == 0L)
{
Console.WriteLine("Storage Quota: Not applicable");
Console.WriteLine("Free Space Available: Unlimited");
}
else
{
long sitequota = (site.Quota.StorageMaximumLevel / 0x100000L);
long freespace = sitequota - spaceused;
Console.WriteLine("Storage Quota: " + sitequota.ToString());
Console.WriteLine("Free Space Available: " + freespace.ToString() + " MB");
}
Console.WriteLine("Storage Used: " + spaceused + " MB");
}

