Custom Site Usage Report in MOSS 2007:
private void ExecuteButton_Click_Click(object sender, EventArgs e)
{
string relativeUrl = "RelativeUrl";
string sizeInMb = "SizeInMb";
string itemCount = "ItemCount";
string title = "Title";
string size = "Size";
string directory = "Directory";
string leafName = "LeafName";
string vsSiteUsageTable = "SiteUsageTable";
string vsSortDirection = "SortDirection";
string vsSortExpression = "SortExpression";
string ascending = "ASC";
string descending = "DESC";
using (SPSite site = new SPSite(urlText.Text))
{
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));
// dataGridView1.DataSource = table;
//}
DataTable dtDocumentLibrary = site.StorageManagementInformation(SPSite.StorageManagementInformationType.DocumentLibrary, SPSite.StorageManagementSortOrder.Decreasing, SPSite.StorageManagementSortedOn.Size, 100);
DataTable dtList = site.StorageManagementInformation(SPSite.StorageManagementInformationType.List, SPSite.StorageManagementSortOrder.Decreasing, SPSite.StorageManagementSortedOn.Size, 100);
dtDocumentLibrary.Merge(dtList);
if (!dtDocumentLibrary.Columns.Contains(relativeUrl)
&& !dtDocumentLibrary.Columns.Contains(sizeInMb))
{
dtDocumentLibrary.Columns.Add(relativeUrl);
dtDocumentLibrary.Columns.Add(sizeInMb);
}
string webUrl = site.WebApplication.GetResponseUri(Microsoft.SharePoint.Administration.SPUrlZone.Default).AbsoluteUri;
foreach (DataRow dtRow in dtDocumentLibrary.Rows)
{
dtRow[relativeUrl] = string.Format("{0}{1}/{2}", webUrl, dtRow[directory], dtRow[leafName]); ;
dtRow[sizeInMb] = Math.Round(Convert.ToDouble(dtRow[size]) / (1024 * 1024), 3);
}
//ViewState[vsSiteUsageTable] = dtDocumentLibrary;
dataGridView1.DataSource = dtDocumentLibrary;
//dataGridView1.DataBind();
//double siteSize = Math.Round((Convert.ToDouble(site.Usage.Storage)) / 1024 / 1024, 3); /// (1024 * 1024), 3);//consumed by the site collection
decimal siteSize = Convert.ToDecimal((site.Usage.Storage / 1024f) / 1024f);
lblSize.Text = siteSize.ToString();
(1024 * 1024), 3);
//double siteLimitSize = Math.Round((Convert.ToDouble(usage)) / (1024 * 1024), 3);
//lblSizeLimit.Text = siteLimitSize.ToString();
if (site.Quota.StorageMaximumLevel != 0)
{
double siteLimitSize = Math.Round((Convert.ToDouble(site.Quota.StorageMaximumLevel)) / (1024 * 1024), 3);
lblSizeLimit.Text = siteLimitSize.ToString();
}
else
{
lblSizeLimit.Text = "Not Set";
}
}
}
private void ExecuteButton_Click_Click(object sender, EventArgs e)
{
string relativeUrl = "RelativeUrl";
string sizeInMb = "SizeInMb";
string itemCount = "ItemCount";
string title = "Title";
string size = "Size";
string directory = "Directory";
string leafName = "LeafName";
string vsSiteUsageTable = "SiteUsageTable";
string vsSortDirection = "SortDirection";
string vsSortExpression = "SortExpression";
string ascending = "ASC";
string descending = "DESC";
using (SPSite site = new SPSite(urlText.Text))
{
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));
// dataGridView1.DataSource = table;
//}
DataTable dtDocumentLibrary = site.StorageManagementInformation(SPSite.StorageManagementInformationType.DocumentLibrary, SPSite.StorageManagementSortOrder.Decreasing, SPSite.StorageManagementSortedOn.Size, 100);
DataTable dtList = site.StorageManagementInformation(SPSite.StorageManagementInformationType.List, SPSite.StorageManagementSortOrder.Decreasing, SPSite.StorageManagementSortedOn.Size, 100);
dtDocumentLibrary.Merge(dtList);
if (!dtDocumentLibrary.Columns.Contains(relativeUrl)
&& !dtDocumentLibrary.Columns.Contains(sizeInMb))
{
dtDocumentLibrary.Columns.Add(relativeUrl);
dtDocumentLibrary.Columns.Add(sizeInMb);
}
string webUrl = site.WebApplication.GetResponseUri(Microsoft.SharePoint.Administration.SPUrlZone.Default).AbsoluteUri;
foreach (DataRow dtRow in dtDocumentLibrary.Rows)
{
dtRow[relativeUrl] = string.Format("{0}{1}/{2}", webUrl, dtRow[directory], dtRow[leafName]); ;
dtRow[sizeInMb] = Math.Round(Convert.ToDouble(dtRow[size]) / (1024 * 1024), 3);
}
//ViewState[vsSiteUsageTable] = dtDocumentLibrary;
dataGridView1.DataSource = dtDocumentLibrary;
//dataGridView1.DataBind();
//double siteSize = Math.Round((Convert.ToDouble(site.Usage.Storage)) / 1024 / 1024, 3); /// (1024 * 1024), 3);//consumed by the site collection
decimal siteSize = Convert.ToDecimal((site.Usage.Storage / 1024f) / 1024f);
lblSize.Text = siteSize.ToString();
(1024 * 1024), 3);
//double siteLimitSize = Math.Round((Convert.ToDouble(usage)) / (1024 * 1024), 3);
//lblSizeLimit.Text = siteLimitSize.ToString();
if (site.Quota.StorageMaximumLevel != 0)
{
double siteLimitSize = Math.Round((Convert.ToDouble(site.Quota.StorageMaximumLevel)) / (1024 * 1024), 3);
lblSizeLimit.Text = siteLimitSize.ToString();
}
else
{
lblSizeLimit.Text = "Not Set";
}
}
}
1. this code retrieve the site usage storage data.
2. list and library wise code retrieve the checkin and checkout files data.
3. its means whenever checkout the file that item available two places one is version history and other is SharePoint draft folder in local machine.