今天一个朋友问起我, 如何查看它的站点的空间使用情况.
首先, 你需要在管理中心中给站点指定一个配额(Quota).
1. 在管理中心中先建立一个quota template.
2. 点击Site collection quotas and locks. 选中一个site collection.
3. 给这个站点集指定一个quota template.
4. 然后在站点集的网站设置页面中, 就可以看到如下的链接: Storage space allocation出现了.
5. 点击这个链接, 你就可以进入下面的页面, 查看站点集内的任何文档库, 列表, 和文档的大小了.
通过代码, 你也可以得到相同的结果, 代码如下:
SPSite oSite = new SPSite("http://blr3r7-19c:13774/sites/testwp"); DataTable oDtRawData = null; // this line of code will return the stroage information of all the document lirbaries in this site oDtRawData = oSite.StorageManagementInformation( SPSite.StorageManagementInformationType.DocumentLibrary, SPSite.StorageManagementSortOrder.Increasing, SPSite.StorageManagementSortedOn.Size, 100); // this line of code will return the stroage information of all the lists in this site oDtRawData = oSite.StorageManagementInformation( SPSite.StorageManagementInformationType.List, SPSite.StorageManagementSortOrder.Increasing, SPSite.StorageManagementSortedOn.Size, 100); // this line of code will return the stroage information of all the Documents in this site oDtRawData = oSite.StorageManagementInformation( SPSite.StorageManagementInformationType.Document, SPSite.StorageManagementSortOrder.Increasing, SPSite.StorageManagementSortedOn.Size, 100); // 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); } Console.ReadLine(); // loop through all the rows and find out the values. Here the size will be return in bytes (size/1024 = size in KBs) foreach (DataRow oRow in oDtRawData.Rows) { Console.WriteLine(oRow["Title"].ToString() + " : " + oRow["Size"].ToString() + " : " + oRow["LeafName"].ToString()); } Console.ReadLine(); }
第二种方法, 使用stsadm命令: stsadm -o enumsites -url http://testserver/
输出结果举例:
<Sites Count="1"> <Site Url="http://testserver" Owner="domain\mossadmin" ContentDatabase="WSS_ Content_80" StorageUsedMB="8.9" StorageWarningMB="150" StorageMaxMB="200" / > </Sites>
第三种方法, 使用Object Model.
string siteCollectionURL = "http://testserver/"; // Site Collection URL SPSiteAdministration st = new SPSiteAdministration(siteCollectionURL); float scDiskUsage = st.DiskUsed; float a = (scDiskUsage / (1024 * 1024));
注意: 这里得到的全部都是站点集的大小.
如何得到子站点的大小呢?
======================
方法是使用Object Model, 代码如下:
public void GetSubSiteSize() { string siteCollectionURL = ""; // Site Collection URL SPSite oSPSite = new SPSite(siteCollectionURL); SPWeb oSPWeb = oSPSite.RootWeb; float totalSiteDiskUsage = GetWebSize(oSPWeb); string filePath = @"C:\MyFile.txt"; // File Path FileStream sb = new FileStream(filePath, FileMode.Create); StreamWriter sw = new StreamWriter(sb); sw.Write(str); sw.Close(); } private float GetWebSize(SPWeb web) { float total = 0; foreach (SPFolder folder in web.Folders) { total += GetFolderSize(folder); } foreach (SPWeb subweb in web.Webs) { total += GetWebSize(subweb); subweb.Dispose(); } if (!web.IsRootWeb) { str += "Site url : " + web.Url + "\r\n"; str += "Size : " + (total / (1024 * 1024)) + " MB" + "\r\n"; str += "\r\n"; } return total; } private float GetFolderSize(SPFolder folder) { float folderSize = 0; foreach (SPFile file in folder.Files) { folderSize += file.Length; } foreach (SPFolder subfolder in folder.SubFolders) { folderSize += GetFolderSize(subfolder); } return folderSize; }
参考资料:
Check quota data for a site
http://office.microsoft.com/en-us/sharepointtechnology/HA101577661033.aspx
SharePoint Quota Management
http://nextconnect.blogspot.com/2009/06/sharepoint-quota-management.html
STSADM EnumSites Operation Reports Actual Site Storage space as ZERO for an actively used site
WSS - How to get site size? Site collection site? Workspace site? - WSS
How to find out the storage space allocation details a site through code.