SPSite.GetChanges Method (SPChangeToken)

Returns a collection of changes, starting from a particular point in the change log.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

public SPChangeCollection GetChanges(
	SPChangeToken changeToken


Type: Microsoft.SharePoint.SPChangeToken

An SPChangeToken object that specifies a starting date and time. An SPException exception is thrown if the token refers to a time before the start of the current change log. To start at the beginning of the change log, pass a a null reference (Nothing in Visual Basic) token.

Return Value

Type: Microsoft.SharePoint.SPChangeCollection
A collection of SPChange objects that represent the changes.

You can get an SPChangeToken object to pass as an argument to this method by extracting one from the ChangeToken property of the last change returned by a previous call to the GetChanges method. Or you can use the SPChangeToken constructor to create a new change token.

If you construct an SPChangeToken object to use with this method, pass SPChangeCollection.CollectionScope.Site as the constructor’s first argument, the value of the current object’s SPSite.ID property as the second argument, and a DateTime object as the third argument.


By default, the change log retains data for 60 days. You can configure the retention period by setting the ChangeLogRetentionPeriod property.

The following example is a console application that demonstrates how to get all changes in the log. The program loops while getting changes in batches and breaks out of the loop when it retrieves a collection with zero members, signifying that it has reached the end of the log.

using System;
using Microsoft.SharePoint;

namespace Test
   class ConsoleApp
      static void Main(string[] args)
         using (SPSite site = new SPSite("http://localhost"))
            long total = 0;
            SPChangeToken token = null;

            // Get the first batch of changes.
            SPChangeCollection changes= site.GetChanges(token);

            // Loop until the end of the log is reached.
            while (changes.Count > 0)
               total += changes.Count;

               foreach (SPChange change in changes)
                  string str = change.ChangeType.ToString();

               changes= site.GetChanges(token);
               token = changes.LastChangeToken;

            Console.WriteLine("Total changes = {0:#,#}", total);
         Console.Write("\nPress ENTER to continue...");