Querying the Change Log for Specific Changes

Applies to: SharePoint Foundation 2010

You can narrow the selection of changes that are returned in a change collection by passing an SPChangeQuery object to an overload of the GetChanges method of the SPList, SPWeb, SPSite, or SPContentDatabase class. When you construct an SPChangeQuery object, you can specify that you want to filter the results of the query by object type, or by change type, or by both.

Constructing a Query

To filter the results that are returned by a call to the GetChanges(SPChangeQuery) method, use the parameters of the SPChangeQuery constructor in combination with the SPChangeQuery object's properties.

The signature of the constructor is as follows:

public SPChangeQuery(bool AllChangeObjectTypes, bool AllChangeTypes);

Here is how to use the two parameters of the constructor:

  • AllChangeObjectTypes

    Pass true to return changes to all object types. Pass false to limit the query to specific types of objects; then set true in the properties of the SPChangeQuery object that correspond to the object types that you are interested in.

    For example, the following code constructs a query for changes to SPGroup objects.

    // Construct a query.
    SPChangeQuery query = new SPChangeQuery(false, true); 
    
    // Specify the object type. 
    query.Group = true;
    
  • AllChangeTypes

    Pass true to return all types of changes. Pass false to limit the query to specific types of changes; then set true in the properties of the SPChangeQuery object that correspond to the types of changes that you are interested in.

    For example, the following code constructs a query for changes that delete objects.

    // Construct a query.
    SPChangeQuery query = new SPChangeQuery(true, false); 
    
    // Specify the change type. 
    query.Delete = true;
    

If you want to constrain the query to specific types of changes to specific types of objects, you can pass false as the argument to both parameters. For example, the following code constructs a query for changes that add, delete, or update list items.

// Construct a query.
SPChangeQuery query = new SPChangeQuery(false, false); 

// Specify the object type.
query.Item = true;

// And the change types. 
query.Add = true;
query.Delete = true;
query.Update = true;

Filtering by Object Type

The following table is a list of the properties of the SPChangeQuery class that you can use to specify the types of objects for which changes should be returned. To get changes for a particular type of object, set the corresponding property to true. Change entries are returned as subclasses of SPChange with properties specific to the object type. For example, the SPChangeUser subclass represents a change to an SPUser object and has an IsSiteAdminChange property that describes a characteristic of a change to that type of object.

Table 1. Properties that specify an object type

Property

Description

Subclass Returned

Alert

Include changes to SPAlert objects.

SPChangeAlert

ContentType

Include changes to SPContentType objects.

SPChangeContentType

Field

Include changes to SPField objects.

SPChangeField

File

Include changes to files that exist outside of a list and do not have corresponding items.

SPChangeFile

Folder

Include changes to folders that exist outside of a list and do not have corresponding items.

SPChangeFolder

Group

Include changes to SPGroup objects.

SPChangeGroup

Item

Include changes to all objects that exist in a list: list items, files, and folders.

SPChangeItem

List

Include changes to SPList objects.

SPChangeList

SecurityPolicy

Include changes to security policy made at the Web application level that affects the entire content database.

SPChangeSecurityPolicy

Site

Include changes to SPSite objects.

SPChangeSite

User

Include changes to SPUser objects.

SPChangeUser

View

Include changes to SPView objects.

SPChangeView

Web

Include changes to SPWeb objects.

SPChangeWeb

Filitering by Change Type

The following table is a list of the properties of the SPChangeQuery class that you can use to specify the types of changes to objects that a query should return. To get a particular type of change, set the corresponding property to true. Keep in mind, however, that not all types of changes apply to all types of objects.

Table 2. Properties that specify a type of change

Property

Description

Add

Include object additions. For items, files, and folders, the TimeLastModified value in the log should be the same as the Created property of the object.

Delete

Include object deletions.

GroupMembershipAdd

Include changes that add users to groups.

GroupMembershipDelete

Include changes the remove users from groups.

Move

Include move operations.

Navigation

Include changes to navigation.

Rename

Include renaming changes. This means that the file name portion of the URL was changed.

Restore

Include changes that restore objects from the Recycle Bin or from a backup. The restore change signals to the change-log reader of a sync client that it must resynchronize the object and all its children.

RoleAssignmentAdd

Include changes that add a role assignment at the scope of the object.

RoleAssignmentDelete

Include changes that remove a role assignment at the scope of the object.

RoleDefinitionAdd

Include changes that add a role definition.

RoleDefinitionDelete

Include changes that delete a role definition.

RoleDefinitionUpdate

Include changes that modify a role definition.

SystemUpdate

Include changes that modify an object without its Modified or Modified By property changing. The TimeLastModified value in the log should be the time that the update occurred, not the Modified property.

Update

Include changes that modify an object.

See Also

Tasks

How to: Filter the Change Log by Object Type

How to: Filter the Change Log by Change Type