Have You ever wondered how to check quota miniumum and warning level values or current storage usage?

It’s very simple and it can be done with few lines of code.

Below You can find a sample how to get mentioned values in mega bytes unit:

SPSite site = SPContext.Current.Site;
decimal currentUsage = Convert.ToDecimal((site.Usage.Storage / 1024f) / 1024f);
decimal maximumLevel = Convert.ToInt32((site.Quota.StorageMaximumLevel / 1024f) / 1024f);
decimal warningLevel = Convert.ToInt32((site.Quota.StorageWarningLevel / 1024f) / 1024f);

Ofcourse, user who will run this code has to have high privileges, otherwise an exception will be thrown. To avoid this situation You can use SPSecurity.RunWithElevatedPriviliges to get a reference to a SPSite object.