using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System.IO;
using System.Web;
using System.Text.RegularExpressions;
using System.Data;
namespace GetAllWebsSize_documents
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("This tool is designed for find the size of each website and site in all Site collection.");
InitionFile();
Console.WriteLine("Please input the web url:");
String weburl = Console.ReadLine();
Uri webAppUri = new Uri(weburl);
SPWebApplication webApplication = SPWebApplication.Lookup(webAppUri);
Console.WriteLine("Title\tSize(MB)\tLastModifiedTime\tWebUrl");
writer.WriteLine("Title\tSize(MB)\tLastModifiedTime\tWebUrl");
foreach (SPSite site in webApplication.Sites)
{
DataTable oDtRawData = null;
oDtRawData = site.StorageManagementInformation(SPSite.StorageManagementInformationType.DocumentLibrary, SPSite.StorageManagementSortOrder.Decreasing, SPSite.StorageManagementSortedOn.Size, 0);
/* /// if you wan to see column names, loop through all the columns and find out the names and grab the needed one.
foreach (DataColumn oColumn in oDtRawData.Columns)
{
Console.WriteLine(oColumn.ColumnName);
}
*/
foreach (SPWeb web in site.AllWebs)
{
Int64 sizes = 0;
foreach (DataRow oRow in oDtRawData.Rows)
{
string oRowWebGuid = oRow["WebGuid"].ToString().ToLower();
string webId= "{"+web.ID.ToString()+"}";
if (oRowWebGuid == webId)
{
string size1 = oRow["Size"].ToString();
Int64 size = Convert.ToInt64(size1);
// Console.WriteLine("Processing......" + oRowWebGuid + "......" + webId);
sizes = sizes + size;
// writer.WriteLine(oRow["LeafName"].ToString() + "\t" + size + "\t" + oRow["WebUrl"].ToString());
}
}
Console.WriteLine(web.Title + "\t" + Math.Round(sizes / 1024.0f / 1024.0f, 2) + "\t" + web.LastItemModifiedDate + "\t" + web.Url);
writer.WriteLine(web.Title + "\t" + Math.Round(sizes / 1024.0f / 1024.0f, 2) + "\t" + web.LastItemModifiedDate + "\t" + web.Url);
}
}
CloseFile();
// Console.ReadKey();
}
static StreamWriter writer;
static void InitionFile()
{
writer = new StreamWriter("files.txt", false);
}
static void CloseFile()
{
writer.Flush();
writer.Close();
}
static void WriteLine(string msg)
{
writer.WriteLine(msg);
}
}
}