SPList.GetChanges - Méthode (SPChangeToken, SPChangeToken)

Returns a collection of changes logged over a specified period of time.

Espace de noms :  Microsoft.SharePoint
Assembly :  Microsoft.SharePoint (dans Microsoft.SharePoint.dll)

Syntaxe

'Déclaration
Public Function GetChanges ( _
    changeToken As SPChangeToken, _
    changeTokenEnd As SPChangeToken _
) As SPChangeCollection
'Utilisation
Dim instance As SPList
Dim changeToken As SPChangeToken
Dim changeTokenEnd As SPChangeToken
Dim returnValue As SPChangeCollection

returnValue = instance.GetChanges(changeToken, _
    changeTokenEnd)
public SPChangeCollection GetChanges(
    SPChangeToken changeToken,
    SPChangeToken changeTokenEnd
)

Paramètres

Valeur renvoyée

Type : Microsoft.SharePoint.SPChangeCollection
The changes.

Exceptions

Exception Condition
SPException

changeToken or changeTokenEnd is not a valid token.

Remarques

When you construct the SPChangeToken objects to use with this method, pass SPChangeCollection.CollectionScope.List as the constructor’s first argument, the value of the current object’s SPList.ID property as the second argument, and a DateTime object as the third argument.

In addition, the following rules apply:

  • If either token refers to a time before the start of the current change log, the method throws an exception.

  • If the time of the second token is before the time of the first token, the method returns an empty collection.

  • Si le premier jeton est une référence Null (Rien dans Visual Basic), la collection des modifications qui est retournée commence au début du journal des modifications actuel.

  • Si le second jeton est une référence Null (Rien dans Visual Basic), la collection des modifications qui est retournée inclut toutes les modifications après la date du premier jeton des modifications, jusqu'à la limite pour une collection unique. Si plus de modifications se sont produites au cours de cette période, le premier lot est retourné.

Notes

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

Exemples

The following example is a console application that queries the change log for changes to a list during a period of seven days. After retrieving the changes, the application prints information about each change to the console.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://localhost"))
         {
            using (SPWeb webSite = siteCollection.OpenWeb())
            {
               // Get a list.
               SPList list = webSite.Lists[0];

               SPChangeToken startToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.List,
                  list.ID,
                  new DateTime(2008, 10, 12));

               SPChangeToken endToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.List,
                  list.ID,
                  new DateTime(2008, 10, 18));


               SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;
               int total = 0;

               // Get the first batch of changes.
               SPChangeCollection changes = list.GetChanges(startToken, endToken);

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

                  // Print info about each change to the console.
                  foreach (SPChange change in changes)
                  {
                     Console.WriteLine("\nDate: {0}",
                         timeZone.UTCToLocalTime(change.Time).ToString());
                     Console.WriteLine("Object type: {0}", change.GetType().ToString());
                     Console.WriteLine("Change: {0}", change.ChangeType.ToString());
                  }

                  // Go get another batch.
                  startToken = changes.LastChangeToken;
                  changes = list.GetChanges(startToken, endToken);
               }

               Console.WriteLine("\nTotal of {0} changes to {1} list", total, list.Title);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.ReadLine();
      }
   }
}
Imports System
Imports Microsoft.SharePoint

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

            ' Get a list.
            Dim list As SPList = webSite.Lists(0)

            Dim startToken As New SPChangeToken(SPChangeCollection.CollectionScope.List, _
                                                list.ID, _
                                                New DateTime(2008, 10, 12))

            Dim endToken As New SPChangeToken(SPChangeCollection.CollectionScope.List, _
                                              list.ID, _
                                              New DateTime(2008, 10, 18))

            Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone
            Dim total As Integer = 0

            ' Get the first batch of changes.
            Dim changes As SPChangeCollection = list.GetChanges(startToken, endToken)

            ' Loop until we reach the end of the log.
            While changes.Count > 0

               total += changes.Count

               ' Print info about each change to the console.
               For Each change As SPChange In changes
                  Console.WriteLine(vbCrLf + "Date: {0}", timeZone.UTCToLocalTime(change.Time).ToString())
                  Console.WriteLine("Object type: {0}", change.GetType().ToString())
                  Console.WriteLine("Change: {0}", change.ChangeType.ToString())
               Next change

               ' Go get another batch of changes starting where we left off.
               startToken = changes.LastChangeToken
               changes = list.GetChanges(startToken, endToken)

            End While

            Console.WriteLine(vbCrLf + "Total of {0:#,#} changes to {1} list", total, list.Title)

         End Using
      End Using

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

   End Sub
End Module

Voir aussi

Référence

SPList classe

SPList - Membres

GetChanges - Surcharge

Microsoft.SharePoint - Espace de noms

Autres ressources

Using the Change Log