How to find out the storage space allocation details a site through code.

SharePoint has a cool and great facility called Quota templates. In order to get this facility in UI, you have to do the following. Refer:

Enable the site collection quotas in the central administration site – under application management.


Once you click on the “site collection quotas and locks” you will be redirecting to another page and there you can set your quota template and lock status.


Once you enable this one, then you can see a new link under the site collection administration section of your site.


Once you click on that link it will redirect to another beautiful page which is given below.


In the above page we can see all document libraries, documents and lists by selecting the “show only” drop down. Also here we can filter the result using the “Show items” drop down and also we can sort the list items using “Sort By” drop down.

The list will show the name of the list or library and the corresponding size and related information. Now we can see how we can retrieve this information through code. The below code is self explanatory and I believe it won’t confuse you any more J

We can go with the code if you want to create a custom view representation of this detail. Also it will help us if you want to get this information anywhere in your custom application.

   1: SPSite oSite = new SPSite("http://blr3r7-19c:13774/sites/testwp");
   2: DataTable oDtRawData = null;
   4: // this line of code will return the stroage information of all the document lirbaries in this site
   5: oDtRawData = oSite.StorageManagementInformation(SPSite.StorageManagementInformationType.DocumentLibrary,SPSite.StorageManagementSortOrder.Increasing, SPSite.StorageManagementSortedOn.Size,100);
   7: // this line of code will return the stroage information of all the lists in this site
   8: oDtRawData = oSite.StorageManagementInformation(SPSite.StorageManagementInformationType.List, SPSite.StorageManagementSortOrder.Increasing, SPSite.StorageManagementSortedOn.Size, 100);
  10: // this line of code will return the stroage information of all the Documents in this site
  11: oDtRawData = oSite.StorageManagementInformation(SPSite.StorageManagementInformationType.Document, SPSite.StorageManagementSortOrder.Increasing, SPSite.StorageManagementSortedOn.Size, 100);
  13: // if you wan to see column names, loop through all the columns and find out the names and grab the needed one. 
  14: foreach (DataColumn oColumn in oDtRawData.Columns)
  15:    {
  16:             Console.WriteLine(oColumn.ColumnName);                
  17:    }
  18: Console.ReadLine();
  20: // loop through all the rows and find out the values. Here the size will be return in bytes (size/1024 = size in KBs)
  21:   foreach (DataRow oRow in oDtRawData.Rows)
  22:    {
  23:          Console.WriteLine(oRow["Title"].ToString() + " : " + oRow["Size"].ToString() + " : " + oRow["LeafName"].ToString());               
  24:    }
  26: Console.ReadLine();  

Comments (5)

  1. Jenny says:

    I want to be able to find out the size of each site w/in my site collection and can’t seem to find out how – ugggh!

  2. sowmyancs says:

    per my knowledge there is no a straight way to find out it. Otherway would be take that site out and put it in a new site collection through export/import, however it will be a bad work-around 🙂  

  3. Tim Dobrinski says:

    I’ve written an app that uses will let you see the size of a site in a site collection.  It uses the methods described above.

Skip to main content