Click here to Skip to main content
15,884,388 members
Articles / Programming Languages / C#

Library and List Size

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
8 Nov 2012CPOL3 min read 16.3K   133   2  
How to solve a real life scenario involving retrieving the size of libraries and lists.

Introduction

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

Scenario

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

Image 1

Solution

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 on large site collection execution.
  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.

Image 2

On click of the Execute button, add the following code:

C#
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/.

Following is the screenshot on execution of Squadron:

Image 3

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.

Image 4

For saving the result, please proceed with the next section.

Saving the Report

Squadron provides infrastructure to save the report. You can right click on the grid and choose the Export Data option as shown below:

Image 5

You will be prompted to enter the CSV (Comma Separated Values) file location.

Image 6

After saving, the file gets opened in the appropriate file handler in your machine.

Image 7

Advanced Export

The advanced export feature allows selection of columns while exporting. You can use the Export Data button on the right top end for this purpose. For testing click the User Profile item and then the Execute button.

Image 8

In the appearing screen, choose the columns you would like to export:

Image 9

You can even right click for Check All / Uncheck All options as shown below:

Image 10

After choosing the necessary columns, choose the OK button. You should get the prompt for the CSV file path.

Image 11

After saving, the file gets opened in the register file handler for CSV files.

Image 12

This concludes our exploration of the Advanced Export feature.

References

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 above information is available through Central Administration as well. The method StorageManagementInformation() is a deprecated one and should not be used with a very large row count parameter, 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 future I believe there will be more and more utilities available as the Squadron core is built using a plug-in based architecture.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
United States United States
Jean Paul is a Microsoft MVP and Architect with 12+ years of experience. He is very much passionate in programming and his core skills are SharePoint, ASP.NET & C#.

In the academic side he do hold a BS in Computer Science & MBA. In the certification side he holds MCPD & MCTS spanning from .Net Fundamentals to SQL Server.

Most of the free time he will be doing technical activities like researching solutions, writing articles, resolving forum problems etc. He believes quality & satisfaction goes hand in hand.

You can find some of his work over here. He blogs at http://jeanpaulva.com

Comments and Discussions

 
-- There are no messages in this forum --