This topic has not yet been rated - Rate this topic

SPContentDatabase Class

Represents a content database in the SharePoint Foundation deployment.

Namespace:  Microsoft.SharePoint.Administration
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
[GuidAttribute("3D4F5451-1735-48bb-B920-76C1EC240B1D")]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPContentDatabase : SPDatabase, 
	IDatabaseSnapshotRestore, IMigratable

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.

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

The following example uses the GetChanges method to report when users have been deleted from the current site collection as represented by the current change log.

SPSite siteCollection = SPContext.Current.Site;

SPContentDatabase contentDB = siteCollection.ContentDatabase;

SPChangeQuery myQuery = new SPChangeQuery(false, false);
myQuery.User = true;
myQuery.Delete = true;

SPChangeCollection changes = contentDB.GetChanges(myQuery);

foreach (SPChange change in changes)
{
    Response.Write(" User deleted: " + change.Time.ToString() + "<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)
Community Content Add
Annotations FAQ
RE: access the custom list from the SPContentDatabase?

You could just access it by calling an SPSite/SPWeb then you can create an instance of SPList/SPListItem, etc..


Another way to get information from a specific list to use SPQuery.


I wouldn't use SPContentDatabase for anything other then administrative tasks.

access the custom list from the SPContentDatabase?
Can I access my custom list from the SPContentDatabase? I need to customised report on some columns on the custom list.