SPWeb.GetChanges - Méthode (SPChangeToken)

Obtient les modifications à partir d'un point spécifié dans le journal des modifications.

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

Syntaxe

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

returnValue = instance.GetChanges(changeToken)
public SPChangeCollection GetChanges(
    SPChangeToken changeToken
)

Paramètres

Valeur renvoyée

Type : Microsoft.SharePoint.SPChangeCollection
Les modifications qui ont eu lieu sur le site Web depuis l'emplacement dans le journal de modification spécifié par changeToken.

Exceptions

Exception Condition
SPException

changeToken est null .

Remarques

Pour obtenir un objet SPChangeToken à passer en tant qu'argument à cette méthode, vous pouvez extraire un à partir de la propriété ChangeToken de la dernière modification retournée par un appel précédent à cette méthode. Ou bien, utilisez le constructeur SPChangeToken pour créer un nouveau jeton de modification.

Notes

Par défaut, le journal des modifications conserve les données pendant 60 jours. Pour modifier la période de rétention par défaut, définissez la propriété ChangeLogRetentionPeriod .

Exemples

L'exemple suivant est une application de console qui montre comment obtenir toutes les modifications dans le journal. Le programme effectue une boucle lors de l'obtention des modifications par lots et interrompt la boucle lorsqu'il récupère une collection de membres de 0, ce qui signifie qu'il a atteint la fin du journal.

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.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();
      }
   }
}
Imports System
Imports Microsoft.SharePoint

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

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

            ' Start with a null token so we take changes 
            ' from the beginning of the log
            Dim token As SPChangeToken = Nothing

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

            ' Loop until we get zero changes
            While changes.Count > 0
               total += changes.Count

               For Each change As SPChange In changes
                  ' Process the change
                  Console.WriteLine(vbCrLf + "Date: {0}", timeZone.UTCToLocalTime(change.Time).ToString())
                  Console.WriteLine("Type of change: {0}", change.ChangeType.ToString())
                  Console.WriteLine("Object changed: {0}", change.GetType().ToString())
               Next change

               ' Go get another batch
               token = changes.LastChangeToken
               changes = webSite.GetChanges(token)
            End While

            Console.WriteLine(vbCrLf + "Total = {0:#,#} changes", total)

         End Using
      End Using

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

   End Sub
End Module

Voir aussi

Référence

SPWeb classe

SPWeb - Membres

GetChanges - Surcharge

Microsoft.SharePoint - Espace de noms

CurrentChangeToken

Autres ressources

Using the Change Log