Share via


SPContentDatabase.GetChanges method (SPChangeToken)

Returns the collection of content database changes, starting from a specified date.

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

Syntax

'Declaration
Public Function GetChanges ( _
    changeToken As SPChangeToken _
) As SPChangeCollection
'Usage
Dim instance As SPContentDatabase
Dim changeToken As SPChangeToken
Dim returnValue As SPChangeCollection

returnValue = instance.GetChanges(changeToken)
public SPChangeCollection GetChanges(
    SPChangeToken changeToken
)

Parameters

Return value

Type: Microsoft.SharePoint.SPChangeCollection
A collection of SPChange objects that represent the changes.

Remarks

You can get an SPChangeToken object to pass as an argument to this method by extracting one from the ChangeToken property of the last change returned by a previous call to the GetChanges method. Or, you can use the SPChangeToken constructor to create a new change token.

Note

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

Examples

The following example is a console application that demonstrates how to get all changes in the log. The program loops while getting changes in batches and breaks out of the loop when it retrieves a collection with zero members, signifying that it has reached the end of the list.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://localhost"))
         {
            long total = 0;
            SPChangeToken token = null;

            SPChangeCollection changes = site.ContentDatabase.GetChanges(token);
            while (changes.Count > 0)
            {
               total += changes.Count;

               foreach (SPChange change in changes)
               {
                  // Process change.
                  Console.WriteLine("Date: {0}  Type of object: {1}  Type of change: {2}", 
                     change.Time.ToShortDateString(), change.GetType().ToString(), change.ChangeType);
               }

               token = changes.LastChangeToken;
               changes = site.ContentDatabase.GetChanges(token);
            }

            Console.WriteLine("Total changes = {0:#,#}", total);
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost")

         Dim total As Long = 0
         Dim token As SPChangeToken = Nothing

         Dim changes As SPChangeCollection = site.ContentDatabase.GetChanges(token)
         While changes.Count > 0
            total += changes.Count

            For Each change As SPChange In changes
               ' Process change.
                  Console.WriteLine("Date: {0}  Type of object: {1}  Type of change: {2}", _
                     change.Time.ToShortDateString(), change.GetType().ToString(), change.ChangeType)
            Next change

            token = changes.LastChangeToken
            changes = site.ContentDatabase.GetChanges(token)
         End While

         Console.WriteLine("Total changes = {0:#,#}", total)

      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub

End Module

See also

Reference

SPContentDatabase class

SPContentDatabase members

GetChanges overload

Microsoft.SharePoint.Administration namespace

Other resources

Using the Change Log