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()

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.

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