SPList.GetChanges 方法 (SPChangeToken)
返回从更改日志中的特定位置开始所做更改的集合。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Function GetChanges ( _
changeToken As SPChangeToken _
) As SPChangeCollection
用法
Dim instance As SPList
Dim changeToken As SPChangeToken
Dim returnValue As SPChangeCollection
returnValue = instance.GetChanges(changeToken)
public SPChangeCollection GetChanges(
SPChangeToken changeToken
)
参数
changeToken
类型:Microsoft.SharePoint.SPChangeToken开始日期和时间。若要启动的更改日志的开头,请将此值设置为空引用(无 在 Visual Basic 中)。
返回值
类型:Microsoft.SharePoint.SPChangeCollection
以来的日期和时间changeToken所指定列表中发生的更改。
异常
异常 | 条件 |
---|---|
SPException | changeToken指之前的当前开始更改日志的时间。 |
备注
您可以获取从上次更改由以前调用GetChanges方法返回的ChangeToken属性中提取传递给此方法作为参数的SPChangeToken对象。或者,您可以使用SPChangeToken构造函数来创建新的更改令牌。
备注
默认情况下,更改日志保留 60 天的数据。您可以通过ChangeLogRetentionPeriod属性设置配置的保留期。
示例
下面的示例是一个控制台应用程序演示如何获取日志中的所有更改。程序时批次中获取更改循环,并断开循环时检索表示它已达到列表末尾的零个成员的集合。
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];
int total = 0;
SPChangeToken token = null;
// Get the first batch of changes.
SPChangeCollection changes = list.GetChanges(token);
// Loop until we reach the end of the log.
while (changes.Count > 0)
{
total += changes.Count;
// Go get another batch.
token = changes.LastChangeToken;
changes = list.GetChanges(token);
}
Console.WriteLine("Total 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)
Dim total As Integer = 0
Dim token As SPChangeToken = Nothing
' Get the first batch of changes.
Dim changes As SPChangeCollection = list.GetChanges(token)
' Loop until we reach the end of the log.
While changes.Count > 0
total += changes.Count
' Go get another batch of changes starting where we left off.
token = changes.LastChangeToken
changes = list.GetChanges(token)
End While
Console.WriteLine("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