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 |
Include changes to SPAlert objects. |
||
Include changes to SPContentType objects. |
||
Include changes to SPField objects. |
||
Include changes to files that exist outside of a list and do not have corresponding items. |
||
Include changes to folders that exist outside of a list and do not have corresponding items. |
||
Include changes to SPGroup objects. |
||
Include changes to all objects that exist in a list: list items, files, and folders. |
||
Include changes to SPList objects. |
||
Include changes to security policy made at the Web application level that affects the entire content database. |
||
Include changes to SPSite objects. |
||
Include changes to SPUser objects. |
||
Include changes to SPView objects. |
||
Include changes to SPWeb objects. |
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 |
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. |
|
Include object deletions. |
|
Include changes that add users to groups. |
|
Include changes the remove users from groups. |
|
Include move operations. |
|
Include changes to navigation. |
|
Include renaming changes. This means that the file name portion of the URL was changed. |
|
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. |
|
Include changes that add a role assignment at the scope of the object. |
|
Include changes that remove a role assignment at the scope of the object. |
|
Include changes that add a role definition. |
|
Include changes that delete a role definition. |
|
Include changes that modify a role definition. |
|
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. |
|
Include changes that modify an object. |