Export (0) Print
Expand All

SPWeb.GetChanges method (SPChangeToken)

Gets the changes starting from a specified 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 location in the change log starting at which the changes are returned.

Return value

Type: Microsoft.SharePoint.SPChangeCollection
The changes that have occurred on the website since the location in the change log specified by changeToken.

ExceptionCondition
SPException

changeToken is null .

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

NoteNote

By default, the change log retains data for 60 days. To change the default retention period, set 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 0 members, signifying that it has reached the end of the log.

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)
            {
               SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;
               long total = 0;

               // Start with a null token so we take changes 
               // from the beginning of the log
               SPChangeToken token = null;

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

               // Loop until we get zero changes
               while (changes.Count > 0)
               {
                  total += changes.Count;

                  foreach (SPChange change in changes)
                  {
                     // Process the change
                     Console.WriteLine("\nDate: {0}", timeZone.UTCToLocalTime(change.Time).ToString());
                     Console.WriteLine("Type of change: {0}", change.ChangeType.ToString());
                     Console.WriteLine("Object changed: {0}", change.GetType().ToString()); 
                  }

                  // Go get another batch
                  token = changes.LastChangeToken;
                  changes = webSite.GetChanges(token);
               }
               Console.WriteLine("\nTotal = {0:#,#} changes", total);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Show:
© 2015 Microsoft