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

Retourne une collection de modifications qui ont été consignés sur une période de temps spécifiée.

Espace de noms :  Microsoft.SharePoint.Administration
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 SPContentDatabase
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
Collection d'objets SPChange qui représentent les modifications.

Remarques

Les règles suivantes s'appliquent aux jetons de modification qui sont passés comme arguments.

  • Si l'un des deux jetons désigne un moment se situant avant le début de l'actuel journal des modifications, la méthode lève une exception SPException.

  • Si le moment spécifié par le deuxième jeton intervient avant le moment défini par le premier jeton, la méthode retourne une collection vide.

  • 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

Par défaut, le journal des modifications conserve les données pendant 60 jours. Vous pouvez configurer la période de rétention en définissant la propriété ChangeLogRetentionPeriod .

Exemples

L'exemple suivant est une application console qui interroge le journal modification pour les modifications qui ont eu lieu pendant une période de sept jours. L'application imprime des informations sur chaque modification apportée à la console.

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://localhost"))
         {
            using (SPWeb webSite = siteCollection.RootWeb)
            {
               // We need to do this to get an Id. SPContentDatabase.ID property is obsolete.
               SPPersistedObject db = (SPPersistedObject)siteCollection.ContentDatabase;

               SPChangeToken startToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.ContentDB,
                  db.Id,
                  new DateTime(2008, 11, 17));

               SPChangeToken endToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.ContentDB,
                  db.Id,
                  new DateTime(2008, 11, 23));

               long total = 0;

               SPChangeCollection changes = 
                  siteCollection.ContentDatabase.GetChanges(startToken, endToken);
               while (changes.Count > 0)
               {
                  total += changes.Count;

                  foreach (SPChange change in changes)
                  {
                     Console.WriteLine("\nDate: {0}", change.Time.ToShortDateString());
                     Console.WriteLine("Object type: {0}", change.GetType().ToString());
                     Console.WriteLine("Change type: {0}", change.ChangeType);
                  }

                  startToken = changes.LastChangeToken;
                  changes = siteCollection.ContentDatabase.GetChanges(startToken, endToken);
               }

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

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

            ' We need to do this to get an Id. SPContentDatabase.ID property is obsolete.
            Dim db As SPPersistedObject = CType(siteCollection.ContentDatabase, SPPersistedObject)

            Dim startToken As New SPChangeToken(SPChangeCollection.CollectionScope.ContentDB, _
                                                db.Id, _
                                                New DateTime(2008, 11, 17))

            Dim endToken As New SPChangeToken(SPChangeCollection.CollectionScope.ContentDB, _
                                              db.Id, _
                                              New DateTime(2008, 11, 23))

            Dim total As Long = 0

            Dim changes As SPChangeCollection = _
               siteCollection.ContentDatabase.GetChanges(startToken, endToken)
            While changes.Count > 0
               total += changes.Count

               For Each change As SPChange In changes

                  Console.WriteLine(vbCrLf + "Date: {0}", change.Time.ToShortDateString())
                  Console.WriteLine("Object type: {0}", change.GetType().ToString())
                  Console.WriteLine("Change type: {0}", change.ChangeType)

               Next change

               startToken = changes.LastChangeToken
               changes = siteCollection.ContentDatabase.GetChanges(startToken, endToken)
            End While

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

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub
End Module

Voir aussi

Référence

SPContentDatabase classe

SPContentDatabase - Membres

GetChanges - Surcharge

Microsoft.SharePoint.Administration - Espace de noms

Autres ressources

Using the Change Log