SPWeb.GetChanges method

Gets all of changes listed in the current change log for the website.

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

public SPChangeCollection GetChanges()

Return value

Type: Microsoft.SharePoint.SPChangeCollection
The changes.

The total number of changes returned by a query against the change log can be very large. For performance reasons, changes are returned in batches of up to 2000. This overload method returns only the first batch of changes recorded in the log.

To get all of changes rather than only the first batch, call this method in a loop until it returns a collection with 0 changes, signifying that it has reached the end of the log. Use the ChangeToken property from the last change of the first batch to get the second batch, and so on, until you get an empty collection. For an example, see the GetChanges(SPChangeToken) method.


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

The example is a console application that uses the GetChanges method to create a log file containing information about the first batch of 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 = "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...");