Welcome to MSDN Blogs Sign in | Join | Help

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: http://technet.microsoft.com/en-us/library/cc263223.aspx

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

clip_image002

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.

clip_image004

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

clip_image006

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

clip_image008

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;
   3:             
   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);
   6:  
   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);
   9:  
  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);
  12:             
  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();
  19:  
  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:    }
  25:  
  26: Console.ReadLine();  
Published Saturday, November 15, 2008 4:54 AM by sowmyancs

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# How to find out the storage space allocation details a site through code. | Tmao Coders

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

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

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!

Thursday, January 22, 2009 5:05 PM by Jenny

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

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 :)  

Monday, February 02, 2009 1:04 PM by sowmyancs

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

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.

http://www.thesug.org/blogs/lsuslinky/SSM/Pages/default.aspx

Monday, May 11, 2009 12:15 PM by Tim Dobrinski

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker