Share via


SPChangeToken - Constructeur (SPChangeCollection.CollectionScope, Guid, DateTime)

Initialise une nouvelle instance de la classe SPChangeToken avec une étendue de collection de modification spécifié, identificateur d'objet (ID) et changer la durée.

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

Syntaxe

'Déclaration
Public Sub New ( _
    scope As SPChangeCollection.CollectionScope, _
    scopeId As Guid, _
    changeTime As DateTime _
)
'Utilisation
Dim scope As SPChangeCollection.CollectionScope
Dim scopeId As Guid
Dim changeTime As DateTime

Dim instance As New SPChangeToken(scope, scopeId, _
    changeTime)
public SPChangeToken(
    SPChangeCollection.CollectionScope scope,
    Guid scopeId,
    DateTime changeTime
)

Paramètres

  • changeTime
    Type : System.DateTime

    La date et l'heure d'un changement. Reprises dans le journal des modifications sont spécifiées au format de temps universel coordonné (UTC).

Remarques

Jetons de modification sont spécifiques à une liste particulière, site Web, collection de sites ou base de données de contenu. Lorsque vous construisez un jeton de modification, les valeurs que vous utilisez dans les deux premiers paramètres du constructeur doivent correspondre à l'objet que vous programmez. Par exemple, si vous avez l'intention de passer le jeton de modification à la méthode GetChanges d'un objet SPList , vous devez spécifier SPChangeCollection.CollectionScope.List comme le scope et la valeur de la propriété ID de liste comme le scopeId.

Exemples

L'exemple suivant est une application console qui crée deux jetons de modification afin qu'elle peut interroger le journal modification pour les modifications apportées à une collection de sites pendant une période de sept jours.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite siteCollection = new SPSite("https://localhost"))
         {
            // Create a query.
            SPChangeQuery query = new SPChangeQuery(true, true);

            // Create a change token for the start.
            DateTime startTime = new DateTime(2009, 6, 1);
            query.ChangeTokenStart = new SPChangeToken(SPChangeCollection.CollectionScope.Site,
                                                       siteCollection.ID,
                                                       startTime);
            // Create a change token for the end.
            query.ChangeTokenEnd = new SPChangeToken(SPChangeCollection.CollectionScope.Site,
                                                     siteCollection.ID,
                                                     startTime.AddDays(6));

            // Specify the number of changes per round trip.
            query.FetchLimit = 1000;
            // Keep a running total.
            long total = 0;

            while (true)
            {
               SPChangeCollection changes = siteCollection.GetChanges(query);

               total += changes.Count;

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

               // Break out of the loop if we have the last batch.
               if (changes.Count < query.FetchLimit)
                  break;
               // Otherwise, go get another batch.
               query.ChangeTokenStart = changes.LastChangeToken;
            }

            Console.WriteLine("\nTotal changes = {0:#,#}", 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")

         ' Create a query
         Dim query As New SPChangeQuery(True, True)

         ' Create a change token for the start.
         Dim startTime As New DateTime(2009, 6, 1)
         query.ChangeTokenStart = New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
                                                    siteCollection.ID, _
                                                    startTime)
         ' Create a change token for the end.
         query.ChangeTokenEnd = New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
                                                  siteCollection.ID, _
                                                  startTime.AddDays(6))

         ' Specify the number of changes per round trip.
         query.FetchLimit = 1000

         ' Keep a running total.
         Dim total As Long = 0


         While True

            Dim changes As SPChangeCollection = siteCollection.GetChanges(query)

            total += changes.Count

            For Each change As SPChange In changes

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

            Next change

            ' Break out of loop if we have the last batch.
            If changes.Count < query.FetchLimit Then
               Exit While
            End If

            ' Otherwise, go get another batch.
            query.ChangeTokenStart = changes.LastChangeToken

         End While

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

      End Using

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

   End Sub
End Module

Voir aussi

Référence

SPChangeToken classe

SPChangeToken - Membres

SPChangeToken - Surcharge

Microsoft.SharePoint - Espace de noms