Share via


(SPChangeToken) del método SPWeb.GetChanges

Obtiene los cambios desde un punto especificado en el registro de cambios.

Espacio de nombres:  Microsoft.SharePoint
Ensamblado:  Microsoft.SharePoint (en Microsoft.SharePoint.dll)

Sintaxis

'Declaración
Public Function GetChanges ( _
    changeToken As SPChangeToken _
) As SPChangeCollection
'Uso
Dim instance As SPWeb
Dim changeToken As SPChangeToken
Dim returnValue As SPChangeCollection

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

Parámetros

Valor devuelto

Tipo: Microsoft.SharePoint.SPChangeCollection
Los cambios que se han producido en el sitio Web desde la ubicación en el registro de cambios especificaron por changeToken.

Excepciones

Excepción Condición
SPException

changeToken es nulo .

Comentarios

Para obtener un objeto SPChangeToken a pasar como un argumento a este método, extraer uno de la propiedad ChangeToken del último cambio devuelto por una llamada anterior a este método. O bien, use el constructor SPChangeToken para crear un nuevo token de cambio.

Nota

De forma predeterminada, el registro de cambios conserva los datos durante 60 días. Para cambiar el período de retención predeterminado, establezca la propiedad ChangeLogRetentionPeriod .

Ejemplos

En el siguiente ejemplo es una aplicación de consola que muestra cómo obtener todos los cambios realizados en el registro. El sistema realiza un bucle al obtener los cambios en lotes y rompe el bucle cuando recupera una colección de miembros de 0, lo que significa que ha alcanzado el final del registro.

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

Vea también

Referencia

clase SPWeb

Miembros SPWeb

Sobrecarga GetChanges

Espacio de nombres Microsoft.SharePoint

CurrentChangeToken

Otros recursos

Using the Change Log