0

我已将内容数据库的大小限制为 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# 的集合大小。我做得对吗?如果我做错了什么,请指导我。如果有人有不同的解决方案,请分享。

4

3 回答 3

0

在这种情况下,C# 使用与 Powershell 基本相同的结构,可以在此处找到一个很好的示例。

using(SPSite site = new SPSite(http://yoursitehere.com/site)
{
    SPSite.UsageInfo usageInfo = site.UsageInfo;
    long storageReq = usageInfo.Storage;
}

如果您需要遍历内容数据库中的每个站点,只需调用内容数据库对象并引用其.sites属性即可。

于 2013-05-20T03:25:58.237 回答
0

这个问题在这里得到了回答http://social.msdn.microsoft.com/forums/en-us/sharepointdevelopment/thread/0d066e9b-f6b9-49bc-b741-fcf7abdc854b

于 2013-05-16T07:39:27.927 回答
0

看看这里的两个解决方案:同时存在 powershell 和 c# 解决方案,即获取集合大小的 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);
        }
    }

您可以使用以下内容获取总数据库大小等(取自此处):

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);
于 2013-05-16T07:48:11.377 回答