Share via


SPWeb.GetChanges method (SPChangeToken)

Obtém as alterações a partir de um ponto especificado no registro de alterações.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaração
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 retornado

Type: Microsoft.SharePoint.SPChangeCollection
As alterações que ocorreram no site desde o local no log de alteração especificado por changeToken.

Exceptions

Exception Condition
SPException

changeToken é null .

Comentários

Para obter um objeto SPChangeToken para passar como um argumento para esse método, extrai um da propriedade ChangeToken da última alteração retornada por uma chamada anterior a esse método. Ou, use o construtor de SPChangeToken para criar um novo token de alteração.

Dica

Por padrão, o log de alterações retém dados por 60 dias. Para alterar o período de retenção padrão, defina a propriedade ChangeLogRetentionPeriod .

Examples

O exemplo a seguir é um aplicativo de console que demonstra como obter todas as alterações no registro. O programa executa um loop ao obter alterações em lotes e sai do loop quando ele recupera uma coleção com membros 0, significando que atingiu o final do log.

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

Ver também

Referência

SPWeb class

SPWeb members

GetChanges overload

Microsoft.SharePoint namespace

CurrentChangeToken

Outros recursos

Using the Change Log