To find the size of list or document library in sharepoint

The following code can be used to get the size of list or document library

// get the list from its id/ name
SPList currentList = currentWeb.Lists[listId];

if (SPListTemplateType.DocumentLibrary == currentList.BaseTemplate)
{
DataTable currentLib;
currentLib = site.StorageManagementInformation(
SPSite.StorageManagementInformationType.DocumentLibrary,
SPSite.StorageManagementSortOrder.Decreasing,
SPSite.StorageManagementSortedOn.Size,
100);
foreach (DataRow row in currentLib.Rows)
{
if (row["Title"].ToString() == currentList.Title)
{
this.lblListSize.Text = row["Size"].ToString() + " bytes";
}
}
}
else
{
DataTable currentLib;
currentLib = site.StorageManagementInformation(
SPSite.StorageManagementInformationType.List,
SPSite.StorageManagementSortOrder.Decreasing,
SPSite.StorageManagementSortedOn.Size,
100);
foreach (DataRow row in currentLib.Rows)
{
if (row["Title"].ToString() == currentList.Title)
{
this.lblListSize.Text = row["Size"].ToString() + " bytes";
}
}
}

You can even get the size using sharepoint designer by doing the following steps
1) Open site from SharePoint designer
2) Right click on document library tree node, and selectproperties menu item.

Comments