SPChangeQuery.Item-Eigenschaft
Ruft ab einen Boolean -Wert, der angibt, ob Änderungen an der SPListItem -Objekte in der Abfrage enthalten sind.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
'Declaration
Public Property Item As Boolean
Get
Set
'Usage
Dim instance As SPChangeQuery
Dim value As Boolean
value = instance.Item
instance.Item = value
public bool Item { get; set; }
Eigenschaftswert
Typ: System.Boolean
true , um Änderungen an Listenelementen einzubeziehen; andernfalls false. Der Standardwert ist false.
Beispiele
Im folgende Beispiel ist eine Konsolenanwendung, die das Änderungsprotokoll für Änderungen an Elementen in allen Listen in einer Websitesammlung abfragt. Nach dem Abrufen der Änderungen, die Anwendung untersucht jede Änderung und das Datum der Änderung, die URL der Website, den Titel der Liste, den Anzeigenamen des Elements und den Typ der Änderung gedruckt.
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, True)
' Set a limit on the number of changes returned on a single trip.
query.FetchLimit = 500
' object type
query.Item = True
' Convert to local time.
Dim timeZone As SPTimeZone = webSite.RegionalSettings.TimeZone
' total changes
Dim total As Integer = 0
' Loop until we reach the end of the log.
While True
Dim changes As SPChangeCollection = siteCollection.GetChanges(query)
total += changes.Count ' running total
For Each change As SPChangeItem In changes
' Get information we want.
Dim webUrl As String = String.Empty
Dim listTitle As String = String.Empty
Dim itemDisplayName As String = String.Empty
' Get the web site where the change was made.
Using web As SPWeb = siteCollection.AllWebs(change.WebId)
' Url of the web site
webUrl = web.Url
' Get title of the list.
Dim list As SPList = Nothing
Try
list = web.Lists(change.ListId)
listTitle = list.Title
Catch ex As SPException
listTitle = "Unknown"
itemDisplayName = "Unknown"
End Try
' Get display name of the item.
If list IsNot Nothing Then
Try ' Is it an item?
itemDisplayName = _
list.GetItemByUniqueId(change.UniqueId).DisplayName
Catch noItem As ArgumentException
Try ' Is it a folder?
itemDisplayName = _
list.Folders(change.UniqueId).DisplayName
Catch noFolder As ArgumentException ' Must have been deleted
itemDisplayName = "No longer exists"
End Try
End Try
End If
End Using
' Write to the console.
Console.WriteLine(vbCrLf + "Date: {0}", _
timeZone.UTCToLocalTime(change.Time).ToString())
Console.WriteLine("Web site: {0}", webUrl)
Console.WriteLine("List: {0}", listTitle)
Console.WriteLine("Item: {0}", itemDisplayName)
Console.WriteLine("Change: {0}", change.ChangeType)
Next change
' Break out of the 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 of {0:#,#} changes", total)
End Using
End Using
Console.Write(vbCrLf + "Press ENTER to continue...")
Console.ReadLine()
End Sub
End Module
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, true);
// Set a limit on the number of changes returned on a single trip.
query.FetchLimit = 500;
// object type
query.Item = true;
// Convert to local time.
SPTimeZone timeZone = webSite.RegionalSettings.TimeZone;
// total changes
int total = 0;
// Loop until we reach the end of the log.
while (true)
{
SPChangeCollection changes = siteCollection.GetChanges(query);
total += changes.Count; // running total
foreach (SPChangeItem change in changes)
{
// Get information we want.
string webUrl = String.Empty;
string listTitle = String.Empty;
string itemDisplayName = String.Empty;
// Get the web site where the change was made.
using (SPWeb web = siteCollection.AllWebs[change.WebId])
{
// Get url of the web site.
webUrl = web.Url;
// Get title of the list.
SPList list = null;
try
{
list = web.Lists[change.ListId];
listTitle = list.Title;
}
catch (SPException)
{
listTitle = "Unknown";
itemDisplayName = "Unknown";
}
// Get display name of the item.
if (list != null)
{
try // Is it an item?
{
itemDisplayName =
list.GetItemByUniqueId(change.UniqueId).DisplayName;
}
catch (ArgumentException)
{
try // Is it a folder?
{
itemDisplayName =
list.Folders[change.UniqueId].DisplayName;
}
catch (ArgumentException) // Must have been deleted.
{
itemDisplayName = "No longer exists";
}
}
}
}
// Write to the console.
Console.WriteLine("\nDate: {0}",
timeZone.UTCToLocalTime(change.Time).ToString());
Console.WriteLine("Web site: {0}", webUrl);
Console.WriteLine("List: {0}", listTitle);
Console.WriteLine("Item: {0}", itemDisplayName);
Console.WriteLine("Change: {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();
}
}
}