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 Function GetChanges As SPChangeCollection
Dim instance As SPWeb
Dim returnValue As SPChangeCollection

returnValue = instance.GetChanges()
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...");
Imports System
Imports System.IO
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using siteCollection As SPSite = New SPSite("http://localhost")
         Using webSite As SPWeb = siteCollection.RootWeb

            Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone
            Dim fileName As String = "ChangeLog.txt"
            Dim writer As StreamWriter = File.AppendText(fileName)

            Dim changes As SPChangeCollection = webSite.GetChanges()

            For Each change As SPChange In changes
               writer.WriteLine(vbCrLf + "Date: {0}", timeZone.UTCToLocalTime(change.Time).ToString())
               writer.WriteLine("Object type: {0}", change.GetType().ToString())
               writer.WriteLine("Change type: {0}", change.ChangeType)
            Next change

            writer.WriteLine(vbCrLf + "Total changes = {0:#,#}", changes.Count)

            Console.WriteLine("{0} changes written to {1}", changes.Count, fileName)
         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
   End Sub
End Module

See also


SPWeb class

SPWeb members

GetChanges overload

Microsoft.SharePoint namespace

Other resources

Using the Change Log