SPSite.GetChanges method (SPChangeQuery)
從變更記錄檔做為篩選依據指定的查詢會傳回一系列的變更。
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'宣告
Public Function GetChanges ( _
query As SPChangeQuery _
) As SPChangeCollection
'用途
Dim instance As SPSite
Dim query As SPChangeQuery
Dim returnValue As SPChangeCollection
returnValue = instance.GetChanges(query)
public SPChangeCollection GetChanges(
SPChangeQuery query
)
參數
query
Type: Microsoft.SharePoint.SPChangeQuerySPChangeQuery物件,表示查詢。
傳回值
Type: Microsoft.SharePoint.SPChangeCollection
表示變更的SPChange物件的集合。您傳遞的SPChangeQuery物件的FetchLimit屬性設定中的查詢參數,可以調整集合的最大大小。
備註
若要篩選的變更,當您想要只在變更特定的物件,而不是所有的物件,或只在特定物件上的選取動作時使用這個方法。如需詳細資訊,請參閱SPChangeQuery類別的文件。
注意事項 |
---|
根據預設,變更記錄會保留資料的 60 天。您可以藉由設定ChangeLogRetentionPeriod屬性設定的保留期限。 |
Examples
下列範例是主控台應用程式的所有變更記錄都檔的查詢新增、 刪除及更新網站集合中的內容型別上作業。請注意應用程式呼叫GetChanges方法,在迴圈中,擷取批次中的變更,直到在擷取所有的變更。
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)
{
// Construct a query.
SPChangeQuery query = new SPChangeQuery(false, // limit object types
false); // limit change types
// object type
query.ContentType = true;
// change types
query.Add = true;
query.Delete = true;
query.Update = true;
long total = 0;
while (true)
{
SPChangeCollection changes = siteCollection.GetChanges(query);
total += changes.Count;
foreach (SPChangeContentType change in changes)
{
// Get the content type (if it still exists).
SPContentType contentType =
webSite.AvailableContentTypes[change.Id];
// The change might have been to delete the content type.
string contentTypeName;
if (contentType == null)
contentTypeName = "Unknown";
else
contentTypeName = contentType.Name;
Console.WriteLine("\n{0} content type was changed on {1}.",
contentTypeName, change.Time.ToShortDateString());
Console.WriteLine("Type of change: {0}", change.ChangeType.ToString());
}
// 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;
}
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
' Construct a query.
Dim query As New SPChangeQuery(False, False)
' object type
query.ContentType = True
' change types
query.Add = True
query.Delete = True
query.Update = True
Dim total As Long = 0
While True
Dim changes As SPChangeCollection = siteCollection.GetChanges(query)
total += changes.Count
For Each change As SPChangeContentType In changes
' Get the content type (if it still exists).
Dim contentType As SPContentType = _
webSite.AvailableContentTypes(change.Id)
' The change might have been to delete the content type.
Dim contentTypeName As String
If contentType Is Nothing Then
contentTypeName = "Unknown"
Else
contentTypeName = contentType.Name
End If
Console.WriteLine(vbCrLf + "{0} content type was changed on {1}.", _
contentTypeName, change.Time.ToShortDateString())
Console.WriteLine("Type of change: {0}", change.ChangeType.ToString())
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
Console.WriteLine(vbCrLf + "Total changes = {0:#,#}", total)
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
請參閱
參照
Microsoft.SharePoint namespace