初始化与指定的更改集范围、 相应对象标识符 (ID) 和更改时间SPChangeToken类的新实例。
命名空间: Microsoft.SharePoint
程序集: Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)
语法
声明
Public Sub New ( _
scope As SPChangeCollection.CollectionScope, _
scopeId As Guid, _
changeTime As DateTime _
)
用法
Dim scope As SPChangeCollection.CollectionScope
Dim scopeId As Guid
Dim changeTime As DateTime
Dim instance As New SPChangeToken(scope, scopeId, _
changeTime)
public SPChangeToken(
SPChangeCollection.CollectionScope scope,
Guid scopeId,
DateTime changeTime
)
参数
scope
类型:Microsoft.SharePoint.SPChangeCollection.CollectionScope更改令牌,可为列表、 网站、 网站集或内容数据库的范围。
scopeId
类型:System.Guid作用域的 GUID。
changeTime
类型:System.DateTime日期和时间发生的更改。协调世界时 (UTC) 格式中指定的更改日志中的时间。
备注
特定于特定列表、 网站、 网站集或内容数据库的更改令牌。在构造时更改令牌,该构造函数的前两个参数中使用的值应匹配针对编程的对象。例如,如果您想要将更改令牌传递给SPList对象的GetChanges方法,您必须指定SPChangeCollection.CollectionScope.Listscope以及作为scopeId列表ID属性的值。
示例
下面的示例是一个控制台应用程序构造两个更改令牌,以便它可以查询到网站集在七天内的更改的更改日志。
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("https://localhost"))
{
// Create a query.
SPChangeQuery query = new SPChangeQuery(true, true);
// Create a change token for the start.
DateTime startTime = new DateTime(2009, 6, 1);
query.ChangeTokenStart = new SPChangeToken(SPChangeCollection.CollectionScope.Site,
siteCollection.ID,
startTime);
// Create a change token for the end.
query.ChangeTokenEnd = new SPChangeToken(SPChangeCollection.CollectionScope.Site,
siteCollection.ID,
startTime.AddDays(6));
// Specify the number of changes per round trip.
query.FetchLimit = 1000;
// Keep a running total.
long total = 0;
while (true)
{
SPChangeCollection changes = siteCollection.GetChanges(query);
total += changes.Count;
foreach (SPChange change in changes)
{
Console.WriteLine("\nDate: {0}", change.Time.ToShortDateString());
Console.WriteLine("Change subclass: {0}", change.GetType().ToString());
Console.WriteLine("Change type: {0}", change.ChangeType);
}
// Break out of the 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();
}
}
}
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using siteCollection As SPSite = New SPSite("https://localhost")
' Create a query
Dim query As New SPChangeQuery(True, True)
' Create a change token for the start.
Dim startTime As New DateTime(2009, 6, 1)
query.ChangeTokenStart = New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
siteCollection.ID, _
startTime)
' Create a change token for the end.
query.ChangeTokenEnd = New SPChangeToken(SPChangeCollection.CollectionScope.Site, _
siteCollection.ID, _
startTime.AddDays(6))
' Specify the number of changes per round trip.
query.FetchLimit = 1000
' Keep a running total.
Dim total As Long = 0
While True
Dim changes As SPChangeCollection = siteCollection.GetChanges(query)
total += changes.Count
For Each change As SPChange In changes
Console.WriteLine(vbCrLf + "Date: {0}", change.Time.ToShortDateString())
Console.WriteLine("Change subclass: {0}", change.GetType().ToString())
Console.WriteLine("Change type: {0}", change.ChangeType)
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 changes = {0:#,#}", total)
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module