Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
SDK Documentation
General Reference
 Querying for Specific Changes
Community Content
In this section
Statistics Annotations (0)
Querying for Specific Changes

To query for specific change types to a specific type of object, you must set the object and the corresponding event(s) of the SPChangeQuery class. Therefore, to query for the addition of any user to a Web site, set the User and Add properties to true. Setting only User to true does not retrieve all user changes. To query for all types of changes to user objects, you must set the User property and all the possible event properties to true (in other words, Add, Delete, and Update).

Example

The following code example shows how to query for changes to a particular type of object. In this case, all SPUser changes are queried at the content database scope. In the call to the GetChanges method, an SPChangeQuery object is passed that queries for all users added at the database scope.

Visual Basic
Dim database As SPContentDatabase = New SPSite("http://siteUrl").ContentDatabase

' Creating a change token using the time stamp.
Dim startTime As DateTime = DateTime.Now.Subtract(TimeSpan.FromDays(1))
Dim startToken As New SPChangeToken(SPChangeCollection.CollectionScope.ContentDB, database.Id, startTime)
Dim changeQuery As New SPChangeQuery(False, False)
changeQuery.User = True
changeQuery.Add = True
changeQuery.ChangeTokenStart = startToken

' Querying for changes at a later time.
changeQuery.ChangeTokenEnd = database.CurrentChangeToken
Dim changes As SPChangeCollection = database.GetChanges(changeQuery)
Dim change As SPChange

For Each change In changes
    Dim userChange As SPChangeUser = CType(change, SPChangeUser)
    ' Use the SPChangeUser properties e.g. Id to retrieve 
    ' the SPUser object if needed.
Next change

C#
SPContentDatabase database = new SPSite("http://siteUrl").ContentDatabase;

/* Creating a change token using the time stamp.*/
DateTime startTime = DateTime.Now.Subtract(TimeSpan.FromDays(1));
SPChangeToken startToken = new SPChangeToken(SPChangeCollection.CollectionScope.ContentDB, database.Id, startTime);
SPChangeQuery changeQuery = new SPChangeQuery(false, false);
changeQuery.User = true;
changeQuery.Add = true;
changeQuery.ChangeTokenStart = startToken;

/* Querying for changes at a later time.*/
changeQuery.ChangeTokenEnd = database.CurrentChangeToken;
SPChangeCollection changes = database.GetChanges(changeQuery);
foreach (SPChange change in changes)
{
    SPChangeUser userChange = (SPChangeUser)change;
    /* Use the SPChangeUser properties (e.g. Id) to retrieve 
    the SPUser object if needed.*/
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker