de la propiedad SPChangeQuery.ChangeTokenStart
Obtiene o establece un token que especifica la fecha de inicio y hora de los cambios que se devuelven a través de la consulta.
Espacio de nombres: Microsoft.SharePoint
Ensamblado: Microsoft.SharePoint (en Microsoft.SharePoint.dll)
Sintaxis
'Declaración
Public Property ChangeTokenStart As SPChangeToken
Get
Set
'Uso
Dim instance As SPChangeQuery
Dim value As SPChangeToken
value = instance.ChangeTokenStart
instance.ChangeTokenStart = value
public SPChangeToken ChangeTokenStart { get; set; }
Valor de propiedad
Tipo: Microsoft.SharePoint.SPChangeToken
Un objeto SPChangeToken que especifica una fecha y hora de inicio. Se produce una excepción de SPException si el símbolo (token) que hace referencia a una hora antes del inicio del actual registro de cambios. Para comenzar al principio del registro de cambios, establezca la propiedad SPChangeTokenStart en un valor de una referencia null (Nothing en Visual Basic) .
Comentarios
Use el constructor SPChangeToken para crear un token de cambio que se pueden usar para establecer esta propiedad. O bien, para obtener un objeto SPChangeToken , extraiga uno de la propiedad ChangeToken del último cambio devuelto por una llamada anterior al método GetChanges .
Ejemplos
En el siguiente ejemplo es una aplicación de consola que consulta el registro de cambios de los cambios realizados en los elementos de lista de información de usuario de un sitio Web. Tenga en cuenta que la aplicación obtiene los cambios en lotes llamando al método SPWeb.GetChanges en un bucle. La primera vez el bucle, el valor de la propiedad ChangeTokenStart es una referencia null (Nothing en Visual Basic), que indica que la consulta debe comenzar al principio del registro de cambios. En la parte inferior del bucle, el código establece la propiedad ChangeTokenStart al valor del token de cambio para el último cambio en el lote, para que el siguiente lote de cambios comienza donde la dejó la última que.
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using siteCollection As SPSite = New SPSite("https://localhost")
Using webSite As SPWeb = siteCollection.RootWeb
' Construct a query.
Dim query As New SPChangeQuery(False, True)
' Set a limit on the number of changes returned on a single trip.
query.FetchLimit = 500
' object type
query.Item = True
' Get list to query.
Dim list As SPList = webSite.Lists("User Information List")
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
For Each change As SPChangeItem In changes
' Get the item title.
Dim itemName As String = String.Empty
Try
Dim item As SPListItem = list.GetItemByUniqueId(change.UniqueId)
itemName = item.Name
Catch ex As ArgumentException
itemName = "Item not found"
End Try
' Write to the console.
Console.WriteLine(vbCrLf + "Date: {0}", change.Time.ToString())
Console.WriteLine("Change: {0}", change.ChangeType)
Console.WriteLine("Item: {0}", itemName)
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 of {0} changes", total)
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
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)
{
// Construct a query.
SPChangeQuery query = new SPChangeQuery(false, true);
// Set a limit on the number of changes returned on a single trip.
query.FetchLimit = 500;
// object type
query.Item = true;
// list to query
SPList list = webSite.Lists["User Information List"];
int total = 0;
// Loop until we reach the end of the log.
while (true)
{
SPChangeCollection changes = list.GetChanges(query);
total += changes.Count;
foreach (SPChangeItem change in changes)
{
// Get the item title.
string itemName = String.Empty;
try
{
SPListItem item = list.GetItemByUniqueId(change.UniqueId);
itemName = item.Name;
}
catch (ArgumentException)
{
itemName = "Item not found";
}
// Write to the console.
Console.WriteLine("\nDate: {0}", 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 changes = {0:#,#}", total);
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}