SPChangeCollection.LastChangeToken property

Gets the change token that corresponds to the last change in the collection.

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


Public ReadOnly Property LastChangeToken As SPChangeToken
Dim instance As SPChangeCollection
Dim value As SPChangeToken

value = instance.LastChangeToken
public SPChangeToken LastChangeToken { get; }

Property value

Type: Microsoft.SharePoint.SPChangeToken
An SPChangeToken object that represents the last change token.


The change token that is returned is the value of the ChangeToken property of the SPChange object indexed at Count – 1 in the change collection. When you are fetching changes in batches, you can use this token as the starting point for the next batch.


The following example is a simple console application that demonstrates how to retrieve all changes from the current change log.

using System;
using Microsoft.SharePoint;

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

            // Get the first batch of changes.
            SPChangeCollection changes = siteCollection.ContentDatabase.GetChanges(token);
            // Loop until the end of the log is reached.
            while (changes.Count > 0)
               total += changes.Count;

               // Go get another batch.
               token = changes.LastChangeToken;
               changes = siteCollection.ContentDatabase.GetChanges(token);

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

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

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

         ' Get the first batch of changes.
         Dim changes As SPChangeCollection = siteCollection.ContentDatabase.GetChanges(token)

         ' Loop until the end of the log is reached.
         While changes.Count > 0

            total += changes.Count

            ' Go get another batch.
            token = changes.LastChangeToken
            changes = siteCollection.ContentDatabase.GetChanges(token)

         End While

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

      End Using

      Console.Write(vbCrLf + "Press ENTER to continue...")

   End Sub
End Module

See also


SPChangeCollection class

SPChangeCollection members

Microsoft.SharePoint namespace


Other resources

Using the Change Log