SPChangeContentType Class
Represents a change to a content type.
Inheritance Hierarchy
System.Object
Microsoft.SharePoint.SPChange
Microsoft.SharePoint.SPChangeContentType
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Syntax
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public NotInheritable Class SPChangeContentType _
Inherits SPChange
Dim instance As SPChangeContentType
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPChangeContentType : SPChange
Examples
The following example is a console application that queries the change log for all add, delete, and update operations on content types in a site collection. The application enumerates the changes returned by the query and, for each change, reports the name of the changed content type, the date of the change, and the type of change.
Imports System
Imports Microsoft.SharePoint
Module ConsoleApp
Sub Main()
Using siteCollection As SPSite = New SPSite("http://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.ContentDatabase.GetChanges(query)
total += changes.Count
For Each change As SPChange In changes
' Get the content type (if it still exists)
Dim contentTypeChange As SPChangeContentType = CType(change, SPChangeContentType)
Dim contentType As SPContentType = _
webSite.AvailableContentTypes(contentTypeChange.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 < SPChangeCollection.CountLimit Then
Exit While
End If
' Go get another batch of changes starting where we left off
query.ChangeTokenStart = changes((changes.Count - 1)).ChangeToken
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
using System;
using Microsoft.SharePoint;
namespace Test
{
class ConsoleApp
{
static void Main(string[] args)
{
using (SPSite siteCollection = new SPSite("http://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 (SPChange change in changes)
{
// Get the content type (if it still exists)
SPChangeContentType contentTypeChange = (SPChangeContentType)change;
SPContentType contentType =
webSite.AvailableContentTypes[contentTypeChange.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 < SPChangeCollection.CountLimit)
break;
// Otherwise, go get another batch
query.ChangeTokenStart = changes[changes.Count - 1].ChangeToken;
}
Console.WriteLine("\nTotal changes = {0:#,#}", total);
}
}
Console.Write("\nPress ENTER to continue...");
Console.ReadLine();
}
}
}
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.