Share via


(SPChangeQuery) del método SPList.GetChanges

Obtiene los cambios a la lista del registro de cambios con filtrado de la consulta especificada.

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

Sintaxis

'Declaración
Public Function GetChanges ( _
    query As SPChangeQuery _
) As SPChangeCollection
'Uso
Dim instance As SPList
Dim query As SPChangeQuery
Dim returnValue As SPChangeCollection

returnValue = instance.GetChanges(query)
public SPChangeCollection GetChanges(
    SPChangeQuery query
)

Parámetros

Valor devuelto

Tipo: Microsoft.SharePoint.SPChangeCollection
Los cambios se registran para la lista, filtrada por la consulta especificada. El número de cambios que se pueden devolver en una sola colección está limitado por motivos de rendimiento. Puede ajustar el tamaño máximo de la colección estableciendo la propiedad FetchLimit .

Comentarios

Utilice este método para filtrar los cambios cuando se le interesan sólo en los cambios realizados en determinados objetos, en lugar de todos los objetos, o sólo en las acciones seleccionadas en objetos determinados. Para obtener más información acerca de las consultas, vea la clase SPChangeQuery .

Nota

De forma predeterminada, el registro de cambios conserva los datos durante 60 días. Puede configurar el período de retención estableciendo la propiedad ChangeLogRetentionPeriod .

Ejemplos

En el siguiente ejemplo es una aplicación de consola sencilla que consulta el registro de cambios para los elementos que se agrega, actualiza o elimina de una lista especificada. Después de recuperar los cambios, la aplicación examina cada cambio e imprime la fecha de cambio, tipo de cambio y el nombre del elemento que se ha cambiado a la consola.

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];

               // Construct a query.
               SPChangeQuery query = new SPChangeQuery(false,  // limit object types
                                                       false); // limit change types

               // Specify the object type. 
               query.Item = true;

               // Specify change types. 
               query.Add = true;
               query.Delete = true;
               query.Update = true;

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

               // Loop until we reach the end of the log.
               while (true)
               {
                  SPChangeCollection changes = list.GetChanges(query);

                  total += changes.Count;

                  // Print info about each change to the console.
                  foreach (SPChangeItem change in changes)
                  {
                     // Get the item name.
                     string itemName = String.Empty;
                     SPListItem item = null;
                     try
                     {
                        item = list.GetItemByUniqueId(change.UniqueId);
                        itemName = item.Name;
                     }
                     catch (ArgumentException)
                     {
                        itemName = "Unknown";
                     }

                     Console.WriteLine("\nDate: {0}",
                         timeZone.UTCToLocalTime(change.Time).ToString());
                     Console.WriteLine("Change: {0}", change.ChangeType);
                     Console.WriteLine("Item: {0}", itemName);

                  }

                  // Break out of 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 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)

            ' Construct a query
            Dim query As New SPChangeQuery(False, False)

            ' Specify the object type. 
            query.Item = True

            ' Specify change types. 
            query.Add = True
            query.Delete = True
            query.Update = True

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

            ' Loop until we reach the end of the log.
            While True

               Dim changes As SPChangeCollection = list.GetChanges(query)

               total += changes.Count

               ' Print info about each change to the console.
               For Each change As SPChangeItem In changes
                  ' Get the item name.
                  Dim itemName As String = String.Empty
                  Dim item As SPListItem = Nothing
                  Try
                     item = list.GetItemByUniqueId(change.UniqueId) 
                     itemName = item.Name
                  Catch ex As ArgumentException
                     itemName = "Unknown"
                  End Try

                  Console.WriteLine(vbCrLf + "Date: {0}", timeZone.UTCToLocalTime(change.Time).ToString())
                  Console.WriteLine("Change: {0}", change.ChangeType)
                  Console.WriteLine("Item: {0}", itemName)

               Next change

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

               ' Go get another batch of changes starting where we left off.
               query.ChangeTokenStart = changes.LastChangeToken

            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

Vea también

Referencia

clase SPList

Miembros SPList

Sobrecarga GetChanges

Espacio de nombres Microsoft.SharePoint

Otros recursos

Using the Change Log