(SPChangeQuery) del método SPWeb.GetChanges
Obtiene los cambios del registro de cambios filtrado por 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 SPWeb
Dim query As SPChangeQuery
Dim returnValue As SPChangeCollection
returnValue = instance.GetChanges(query)
public SPChangeCollection GetChanges(
SPChangeQuery query
)
Parámetros
query
Tipo: Microsoft.SharePoint.SPChangeQueryLa consulta realizada en el registro de cambios.
Valor devuelto
Tipo: Microsoft.SharePoint.SPChangeCollection
Los cambios que se han producido en el sitio Web basado en la consulta especificada. Especifique el número máximo de cambios para devolver estableciendo la propiedad FetchLimit del parámetro de consulta.
Comentarios
Use este método para obtener los cambios realizados en determinados objetos, en lugar de todos los objetos o sólo para las acciones seleccionadas en objetos determinados. Para obtener más información, vea el la clase SPChangeQuery .
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 crea un archivo de texto con información acerca de los elementos de lista que se han agregado, eliminado o actualizado. La aplicación, llama al método GetChanges en un bucle, la obtención de los cambios en lotes hasta que se hayan recuperado todos los cambios.
using System;
using System.IO;
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, // limit object types
false); // limit change types
// object type
query.Item = true;
// change types
query.Add = true;
query.Delete = true;
query.Update = true;
SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;
long total = 0;
string fileName = "ItemChanges.txt";
StreamWriter writer = File.AppendText(fileName);
while (true)
{
SPChangeCollection changes = webSite.GetChanges(query);
total += changes.Count;
foreach (SPChangeItem change in changes)
{
// Get the list title
string listTitle = String.Empty;
string itemName = String.Empty;
SPList list = null;
try
{
list = webSite.Lists[change.ListId];
listTitle = list.Title;
}
catch (SPException)
{
listTitle = "Unknown";
}
// Get the item title
if (list != null)
{
SPListItem item = null;
try
{
item = list.GetItemByUniqueId(change.UniqueId);
itemName = item.Name;
}
catch (ArgumentException)
{
itemName = "Unknown";
}
}
// Write to the log
writer.WriteLine("\r\nDate: {0}",
timeZone.UTCToLocalTime(change.Time).ToString());
writer.WriteLine("Change: {0} item", change.ChangeType);
writer.WriteLine("List: {0}", listTitle);
writer.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;
}
writer.WriteLine("\r\nTotal changes = {0:#,#}", total);
writer.Flush();
writer.Close();
Console.WriteLine("{0} changes written to {1}", total, fileName);
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
Imports System
Imports System.IO
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, False)
' object type
query.Item = True
' change types
query.Add = True
query.Delete = True
query.Update = True
Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone
Dim total As Long = 0
Dim fileName As String = "ItemChanges.txt"
Dim writer As StreamWriter = File.AppendText(fileName)
While True
Dim changes As SPChangeCollection = webSite.GetChanges(query)
total += changes.Count
For Each change As SPChangeItem In changes
' Get the list title
Dim listTitle As String = String.Empty
Dim itemName As String = String.Empty
Dim list As SPList = Nothing
Try
list = webSite.Lists(change.ListId)
listTitle = list.Title
Catch ex As SPException
listTitle = "Unknown"
End Try
' Get the item title
If list IsNot Nothing Then
Dim item As SPListItem = Nothing
Try
item = list.GetItemByUniqueId(change.UniqueId)
itemName = item.Name
Catch ex As ArgumentException
itemName = "Unknown"
End Try
End If
' Write to the log
writer.WriteLine(vbCrLf + "Date: {0}", _
timeZone.UTCToLocalTime(change.Time).ToString())
writer.WriteLine("Change: {0} item", change.ChangeType)
writer.WriteLine("List: {0}", listTitle)
writer.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
writer.WriteLine(vbCrLf + "Total changes = {0:#,#}", total)
writer.Flush()
writer.Close()
Console.WriteLine("{0} changes written to {1}", total, fileName)
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
Vea también
Referencia
Espacio de nombres Microsoft.SharePoint