Export (0) Print
Expand All

SPList.GetChanges method (SPChangeToken)

Returns a collection of changes starting from a particular point in the change log.

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

public SPChangeCollection GetChanges(
	SPChangeToken changeToken
)

Parameters

changeToken
Type: Microsoft.SharePoint.SPChangeToken

The starting date and time. To start at the beginning of the change log, set this value to a null reference (Nothing in Visual Basic).

Return value

Type: Microsoft.SharePoint.SPChangeCollection
The changes that have occurred in the list since the date and time specified by changeToken.

ExceptionCondition
SPException

changeToken refers to a time before the start of the current change log.

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.

NoteNote

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

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 siteCollection = new SPSite("http://localhost"))
         {
            using (SPWeb webSite = siteCollection.OpenWeb())
            {
               // Get a list.
               SPList list = webSite.Lists[0];

               int total = 0;
               SPChangeToken token = null;

               // Get the first batch of changes.
               SPChangeCollection changes = list.GetChanges(token);

               // Loop until we reach the end of the log.
               while (changes.Count > 0)
               {
                  total += changes.Count;

                  // Go get another batch.
                  token = changes.LastChangeToken;
                  changes = list.GetChanges(token);
               }

               Console.WriteLine("Total of {0:#,#} changes to {1} list", total, list.Title);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Show:
© 2014 Microsoft