SPChangeQuery.ChangeTokenStart Property

Gets or sets a token that specifies the start date and time for changes that are returned through the query.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableAttribute> _
Public Property ChangeTokenStart As SPChangeToken
    Get
    Set
'Usage
Dim instance As SPChangeQuery
Dim value As SPChangeToken

value = instance.ChangeTokenStart

instance.ChangeTokenStart = value
[ClientCallableAttribute]
public SPChangeToken ChangeTokenStart { get; set; }

Property Value

Type: Microsoft.SharePoint.SPChangeToken
An SPChangeToken object that specifies a starting date and time. An SPException exception is thrown if the token refers to a time before the start of the current change log. To start at the beginning of the change log, set the SPChangeTokenStart property to a a null reference (Nothing in Visual Basic) value.

Remarks

Use the SPChangeToken constructor to create a change token that can be used to set this property. Or, get an SPChangeToken object by extracting one from the ChangeToken property of the last change returned by a previous call to the GetChanges method.

Examples

The following example is a console application that queries the change log for changes to items in a Web site's user information list. Note that the application gets changes in batches by calling the SPWeb.GetChanges method in a loop. The first time through the loop, the value of the ChangeTokenStart property is a null reference (Nothing in Visual Basic), which indicates that the query should start at the beginning of the change log. At the bottom of the loop, the code sets the ChangeTokenStart property to the value of the change token for the last change in the batch, so that the next batch of changes begins where the last one left off.

Imports System
Imports Microsoft.SharePoint

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

            ' Construct a query.
            Dim query As New SPChangeQuery(False, True)

            ' Set a limit on the number of changes returned on a single trip.
            query.FetchLimit = 500

            ' object type 
            query.Item = True

            ' Get list to query.
            Dim list As SPList = webSite.Lists("User Information List")

            Dim total As Integer = 0

            ' Loop until we reach the end of the log.
            While True

               Dim changes As SPChangeCollection = list.GetChanges(query)
               total += changes.Count

               For Each change As SPChangeItem In changes
                  ' Get the item title.
                  Dim itemName As String = String.Empty
                  Try
                     Dim item As SPListItem = list.GetItemByUniqueId(change.UniqueId)
                     itemName = item.Name
                  Catch ex As ArgumentException
                     itemName = "Item not found"
                  End Try

                  ' Write to the console.
                  Console.WriteLine(vbCrLf + "Date: {0}", change.Time.ToString())
                  Console.WriteLine("Change: {0}", change.ChangeType)
                  Console.WriteLine("Item: {0}", itemName)
               Next change

               ' Break out of loop if we have the last batch.
               If changes.Count < query.FetchLimit Then
                  Exit While
               End If

               ' Otherwise, go get another batch.
               query.ChangeTokenStart = changes.LastChangeToken

            End While

            Console.WriteLine(vbCrLf + "Total of {0} changes", total)

         End Using
      End Using

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

   End Sub
End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("http://localhost"))
         {
            using (SPWeb webSite = siteCollection.RootWeb)
            {

               // Construct a query.
               SPChangeQuery query = new SPChangeQuery(false, true); 

               // Set a limit on the number of changes returned on a single trip.
               query.FetchLimit = 500;

               // object type 
               query.Item = true;

               // list to query
               SPList list = webSite.Lists["User Information List"];

               int total = 0;

               // Loop until we reach the end of the log.
               while (true)
               {

                  SPChangeCollection changes = list.GetChanges(query);
                  total += changes.Count;

                  foreach (SPChangeItem change in changes)
                  {
                     // Get the item title.
                     string itemName = String.Empty;
                        try
                        {
                           SPListItem item = list.GetItemByUniqueId(change.UniqueId);
                           itemName = item.Name;
                        }
                        catch (ArgumentException)
                        {
                           itemName = "Item not found";
                        }

                     // Write to the console.
                     Console.WriteLine("\nDate: {0}", change.Time.ToString());
                     Console.WriteLine("Change: {0}", change.ChangeType);
                     Console.WriteLine("Item: {0}", itemName);
                  }

                  // Break out of loop if we have the last batch.
                  if (changes.Count < query.FetchLimit)
                     break;

                  // Otherwise, go get another batch.
                  query.ChangeTokenStart = changes.LastChangeToken;
               }

               Console.WriteLine("\nTotal changes = {0:#,#}", total);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}

See Also

Reference

SPChangeQuery Class

SPChangeQuery Members

Microsoft.SharePoint Namespace