2013-05-16 9 views
0

콘텐츠 데이터베이스의 크기를 최대 200GB로 제한했습니다. 다음 코드를 사용하여 콘텐츠 데이터베이스의 크기를 가져 왔습니다.C#을 통해 사이트 모음의 크기를 얻는 방법은 무엇입니까?

static string ConvertToMegabytes(ulong bytes) 
{ 
    return ((decimal)bytes/1024M/1024M).ToString("F1") + "MB"; 
} 

Similary

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); 
나는 100기가바이트 개까지 사이트 모음을 제한합니다. 그래서 난 단지 C#을 사용 모음의 크기를 필요로하는 다음 코드

long bytes = spSite.Usage.Storage; 
double siteCollectionSizeInMB = ConvertBytesToMegabytes(bytes); 

>

static double ConvertBytesToMegabytes(long bytes) 
{ 
    return (bytes/1024f)/1024f; 
} 

을 사용하고 있습니다. 내가 제대로하고 있니? 내가 틀린 일을하고 있다면 나를 안내 해주십시오. 누구든지 다른 솔루션을 가지고 있다면 공유하십시오.

답변

0

봐 : 컬렉션의 크기를 얻을 수있는 C#을 솔루션 즉 Theres both a powershell and c# solution은 다음과 같습니다

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); 
     } 
    } 

당신은 전체 DB를 얻기 위해 다음 사용할 수 있습니다 크기 등 (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); 
0

C 번호는이 경우에서와 본질적으로 같은 파워 쉘 구조를 사용 좋은 예가 here입니다.

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

당신은 단지 콘텐츠 데이터베이스 개체를 호출하고 .sites 속성을 참조, 콘텐츠 데이터베이스의 각 사이트를 통해 반복해야하는 경우.