我将内容数据库的大小限制为200 GB。我使用以下代码来获取内容数据库的大小。
SPWebApplication elevatedWebApp = spWeb.Site.WebApplication;
SPContentDatabaseCollection dbCollection = elevatedWebApp.ContentDatabases;
//Guid id = dbCollection[0].Id;
Guid lastContentDbGuid = new Guid(contentDbGuid);
//SPContentDatabase lastDatabase = dbCollection[dbCollection.Count - 1];
SPContentDatabase lastDatabase = dbCollection[lastContentDbGuid];
ulong dbSize = lastDatabase.DiskSizeRequired;
contentDbMB = ConvertToMegabytes(dbSize);
static string ConvertToMegabytes(ulong bytes)
{
return ((decimal)bytes / 1024M / 1024M).ToString("F1") + "MB";
}
类似我想限制网站集高达100 GB。所以我使用以下代码
long bytes = spSite.Usage.Storage;
double siteCollectionSizeInMB = ConvertBytesToMegabytes(bytes);
>
static double ConvertBytesToMegabytes(long bytes)
{
return (bytes / 1024f) / 1024f;
}
我只需要使用C#的集合大小。我做得对吗?如果我做错了什么,请指导我。如果有人有不同的解决方案,请分享。
答案 0 :(得分:0)
答案 1 :(得分:0)
请看这里的两个解决方案:Theres both a powershell and c# solution,即获取集合大小的C#解决方案是:
SPWebService service = SPFarm.Local.Services.GetValue<SPWebService>();
foreach (SPWebApplication webapp in service.WebApplications)
{
Console.WriteLine("WebApplication : " + webapp.Name);
foreach (SPContentDatabase db in webapp.ContentDatabases)
{
Console.WriteLine("{0}, Nb Sites : {1}, Size : {2}, ", db.Name, db.Sites.Count, db.DiskSizeRequired);
}
}
您可以使用以下内容获取总数据库大小等(Taken from here):
Server srv new Server();
Database db = srv.Databases("MyDatabase");
\\Display size and space information for the database.
Console.WriteLine("data space usage (KB): " + db.DataSpaceUsage.ToString);
Console.WriteLine("index space usage (KB): " + db.IndexSpaceUsage.ToString);
Console.WriteLine("space available (KB): " + db.SpaceAvailable.ToString);
Console.WriteLine("database size (MB): " + db.Size.ToString);
答案 2 :(得分:0)
using(SPSite site = new SPSite(http://yoursitehere.com/site)
{
SPSite.UsageInfo usageInfo = site.UsageInfo;
long storageReq = usageInfo.Storage;
}
如果需要遍历内容数据库中的每个站点,只需调用内容数据库对象并引用其.sites
属性。