This documentation is archived and is not being maintained.

SPWeb.GetChanges Method

Windows SharePoint Services 3

Returns the first 1000 changes listed in the current change log for the Web site.

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

public SPChangeCollection GetChanges()

Return Value

Type: Microsoft.SharePoint.SPChangeCollection
An SPChangeCollection object that represents the changes.

For performance reasons, changes are returned in batches of limited size. The maximum number of changes that a single SPChangeCollection object can contain is specified by the constant CountLimit(), which has a value of 1000. The total number of changes could be very large, depending on the retention period set for the log and the scope of the query. Attempting to fetch all changes in a single round trip could place an unnecessarily high demand on network and server resources.

If you want all changes rather than only the first 1000, your code should call the GetChanges method in a loop until it returns a collection with fewer than 1000, signifying that it has reached the end of the log. You can use the ChangeToken from the last change of the first batch to get the second batch, and so on until you get a batch with fewer than 1000 changes. For an example, see GetChanges(SPChangeToken).


By default, the change log retains data for 15 days. You can configure this in Windows SharePoint Services by using the Web Application General Settings page located on the Central Administration page.

The example is a console application that uses the GetChanges method to create a log file containing information about the first 1000 changes listed in the change log.

using System;
using System.IO;
using Microsoft.SharePoint;

namespace Test
   class ConsoleApp
      static void Main(string[] args)
         using (SPSite siteCollection = new SPSite("http://localhost"))
            using (SPWeb webSite = siteCollection.RootWeb)
               SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;
               string fileName = "C:\\ChangeLog.txt";
               StreamWriter writer = File.AppendText(fileName);

               SPChangeCollection changes = webSite.GetChanges();

               foreach (SPChange change in changes)
                  writer.WriteLine( "\r\nDate: {0}", timeZone.UTCToLocalTime(change.Time).ToString());
                  writer.WriteLine("Object type: {0}", change.GetType().ToString());
                  writer.WriteLine("Change type: {0}", change.ChangeType);

               writer.WriteLine("\r\nTotal changes = {0:#,#}", changes.Count);

               Console.WriteLine("{0} changes written to {1}", changes.Count, fileName);
         Console.Write("\nPress ENTER to continue...");