SPSite.GetChanges method (SPChangeQuery)

Returns a collection of changes from the change log filtered by the specified query.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

public SPChangeCollection GetChanges(
	SPChangeQuery query


Type: Microsoft.SharePoint.SPChangeQuery

An SPChangeQuery object that represents the query.

Return value

Type: Microsoft.SharePoint.SPChangeCollection
A collection of SPChange objects that represent changes. You can adjust the maximum size of the collection by setting the FetchLimit property of the SPChangeQuery object that you pass in the query parameter.

Use this method to filter changes when you are interested only in changes to particular objects, rather than all objects, or only in selected actions on particular objects. For more information, see the documentation for the SPChangeQuery class.


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 queries the change log for all add, delete, and update operations on content types in a site collection. Note that the application calls the GetChanges method in a loop, fetching changes in batches until all changes have been retrieved.

using System;
using Microsoft.SharePoint;

namespace Test
   class ConsoleApp
      static void Main(string[] args)
         using (SPSite siteCollection = new SPSite("http://localhost"))
            using (SPWeb webSite = siteCollection.RootWeb)
               // Construct a query.
               SPChangeQuery query = new SPChangeQuery(false,  // limit object types
                                                       false); // limit change types

               // object type 
               query.ContentType = true;

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

               long total = 0;
               while (true)
                  SPChangeCollection changes = siteCollection.GetChanges(query);

                  total += changes.Count;

                  foreach (SPChangeContentType change in changes)
                     // Get the content type (if it still exists).
                     SPContentType contentType = 

                     // The change might have been to delete the content type.
                     string contentTypeName;
                     if (contentType == null)
                        contentTypeName = "Unknown";
                        contentTypeName = contentType.Name;

                     Console.WriteLine("\n{0} content type was changed on {1}.", 
                                       contentTypeName, change.Time.ToShortDateString());
                     Console.WriteLine("Type of change: {0}", change.ChangeType.ToString());

                  // Break out of loop if we have the last batch.
                  if (changes.Count < query.FetchLimit)
                  // Otherwise, go get another batch.
                  query.ChangeTokenStart = changes.LastChangeToken;

               Console.WriteLine("\nTotal changes = {0:#,#}", total);

         Console.Write("\nPress ENTER to continue...");