Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

SPContentDatabaseCollection Class

Windows SharePoint Services 3

A collection of references to content databases that are used by a single Web application.

System.Object
  Microsoft.SharePoint.Administration.SPAutoSerializingObject
    Microsoft.SharePoint.SPBaseCollection
      Microsoft.SharePoint.Administration.SPContentDatabaseCollection

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
[GuidAttribute("4FFCB8E5-7B15-4b81-AC4E-99A2181AD33E")]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPContentDatabaseCollection : SPBaseCollection

Use the ContentDatabase() property of the SPSite class or of the SPWorkItemCollection class to return the content database for a site collection or work item collection. Use the ContentDatabases property of the SPWebApplication class to return the collection of content databases that are used by the Web application.

To add a content database, use the Add() method.

Use an indexer to return a single content database from the collection. For example, if the collection is assigned to a variable named myContentDatabases, use myContentDatabases[index] in C#, or myContentDatabases(index) in Visual Basic .NET, where index is either the index number of the database in the collection or the GUID for the content database.

The following code example displays information about the content databases of all the SharePoint Web applications within a Windows SharePoint Services server farm.

SPServiceCollection services = SPFarm.Local.Services;

foreach (SPService service in services)
{

    if (service is SPWebService)
    {
        SPWebService webService = (SPWebService)service;
        SPWebApplicationCollection webApplications = webService.WebApplications;

        foreach (SPWebApplication webApplication in webApplications)
        {
            SPContentDatabaseCollection contentDBs = webApplication.ContentDatabases;

            foreach (SPContentDatabase contentDB in contentDBs)
            {
                Response.Write(webApplication.DisplayName + " :: " 
                    + contentDB.CurrentSiteCount.ToString() + " :: " 
                    + contentDB.MaximumSiteCount.ToString() + " :: " 
                    + contentDB.Name + "<BR>");
            }
        }
    }
}

Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread safe.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.