SharePoint 2010 - Quick Retrieval of Site Collection Size

In this article we will see how to solve a real-life scenario involving retrieving the size of libraries & lists.

Scenario

Your customer site collection has exceeded 100 Giga Bytes in size. You are assigned to create a Site Collection Size report that shows the Library & List entries along with the size. The report is crucial for making decisions on possible migration of items into a separate site collection.

Site-Collection- Size-scenario-in-SharePoint.jpg

Solution

The following are the solutions possible:

  1. Iterate through each list / library entries and calculate the size of file, file version, recycle bin. This way would be time-consuming and may timeout for large site collections.
  2. Use the StorageManagementInformation() method for quicker retrieval.

Implementation

For implementing the solution using the second approach:

  • Create a Windows Forms application
  • Add a reference to the Microsoft.SharePoint assembly
  • Set the project property > build > target platform to Any CPU
Add the following controls to the main form:

Implementation-solution-in-SharePoint.jpg

To handle the event of clicking the execute button add the following code:

   private void ExecuteButton_Click(object sender, EventArgs e)

    {

        using (SPSite site = new SPSite(UrlText.Text))

        {

            // Retrieve Document Library entries

            DataTable table = site.StorageManagementInformation(

                SPSite.StorageManagementInformationType.DocumentLibrary,

                SPSite.StorageManagementSortOrder.Decreasing,

                SPSite.StorageManagementSortedOn.Size,

                1000

                );

 

            // Retrieve List entries

            table.Merge(site.StorageManagementInformation(

                SPSite.StorageManagementInformationType.List,

                SPSite.StorageManagementSortOrder.Decreasing,

                SPSite.StorageManagementSortedOn.Size,

                1000)

                );

 

            grid.DataSource = table;

        }

    }

Squadron for SharePoint 2010

A SharePoint utility application is created with the above functionality. You can download it from:

http://squadron2010.codeplex.com/

The following is the screen shot on execution of Squadron:

Squadron-for-SharePoint.jpg

For retrieving Site Collection Size information, click on the Site Size item from the left pane and then the Execute button. You should get the result as shown below.

Site- Collection-Size-result-in-SharePoint.jpg

For saving the result, right-click on the grid and use the Export Data option.

References

http://squadron2010.codeplex.com/

Summary

In this article we have explored a quicker approach in retrieving site collection size entries. I hope the information is useful and please note that the preceding information is available through Central Administration as well. The method StorageManagementInformation() is a deprecated one and should not be used with very large row count parameters, as it may raise memory issues. The source code for the article is attached.  
The Squadron tool is free and it contains other utilities too for working with SharePoint 2010. In the future I believe there will be more and more utilities available as the Squadron core is built using a plugin based architecture.