SPWeb.GetChanges 方法 (SPChangeToken, SPChangeToken)

Gets the changes logged over a specified period of time.

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
Public Function GetChanges ( _
    changeToken As SPChangeToken, _
    changeTokenEnd As SPChangeToken _
) As SPChangeCollection
用法
Dim instance As SPWeb
Dim changeToken As SPChangeToken
Dim changeTokenEnd As SPChangeToken
Dim returnValue As SPChangeCollection

returnValue = instance.GetChanges(changeToken, _
    changeTokenEnd)
public SPChangeCollection GetChanges(
    SPChangeToken changeToken,
    SPChangeToken changeTokenEnd
)

参数

  • changeTokenEnd
    类型:Microsoft.SharePoint.SPChangeToken

    The change token specifying the point in the change log where that change and preceding changes are returned.

返回值

类型:Microsoft.SharePoint.SPChangeCollection
The changes.

异常

异常 条件
SPException

changeToken or changeTokenEnd refers to a point before the start of the current change log.

备注

To construct the SPChangeToken object for this method, pass SPChangeCollection.CollectionScope Web as the constructor’s first argument, the value of the current object’s SPWeb.ID property as the second argument, and a DateTime object as the third argument.

In addition, the following rules apply:

  • If the position of changeTokenEnd in the change log is before the position of changeToken in the change log, this method returns an empty collection.

  • If changeToken is null , the change collection that is returned starts at the beginning of the current change log.

  • If changeTokenEnd is null , the change collection that is returned includes all changes after the position specified by changeToken, up to the limit for a single collection. If more changes occurred in this period, the first batch is returned.

备注

By default, the change log retains data for 60 days. To change the default retention period, set the ChangeLogRetentionPeriod property.

示例

The following example is a console application that queries the change log for changes that took place during a period of seven days. The application then prints information about each change to the console.

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;

               SPChangeToken startToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.Web, 
                  webSite.ID,
                  new DateTime(2008, 11, 17));

               SPChangeToken endToken = new SPChangeToken(
                  SPChangeCollection.CollectionScope.Web, 
                  webSite.ID,
                  new DateTime(2008, 11, 23));

               SPChangeCollection changes = webSite.GetChanges(startToken, endToken);
               while (changes.Count > 0)
               {
                  total += changes.Count;

                  foreach (SPChange change in changes)
                  {
                     Console.WriteLine("\nDate: {0}", timeZone.UTCToLocalTime(change.Time).ToString());
                     Console.WriteLine("Object type: {0}", change.GetType().ToString());
                     Console.WriteLine("Change type: {0}", change.ChangeType);
                  }

                  startToken = changes.LastChangeToken;
                  changes = webSite.GetChanges(startToken, endToken);
               }
               Console.WriteLine("\nTotal changes = {0:#,#}", 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

            Dim startToken As New SPChangeToken(SPChangeCollection.CollectionScope.Web, _
                                                webSite.ID, _
                                                New DateTime(2008, 11, 17))

            Dim endToken As New SPChangeToken(SPChangeCollection.CollectionScope.Web, _
                                              webSite.ID, _
                                              New DateTime(2008, 11, 23))

            Dim changes As SPChangeCollection = webSite.GetChanges(startToken, endToken)
            While changes.Count > 0
               total += changes.Count

               For Each change As SPChange In changes

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

               Next change

               startToken = changes.LastChangeToken
               changes = webSite.GetChanges(startToken, endToken)

            End While

            Console.WriteLine(vbCrLf + "Total changes = {0:#,#}", total)

         End Using
      End Using
      Console.Write(vbCrLf + "Press ENTER to continue...")
      Console.ReadLine()
   End Sub
End Module

另请参阅

引用

SPWeb 类

SPWeb 成员

GetChanges 重载

Microsoft.SharePoint 命名空间

其他资源

Using the Change Log