SPChangeContentType Class
TOC
Collapse the table of content
Expand the table of content
The document is archived and information here might be outdated

SPChangeContentType Class

Windows SharePoint Services 3

Represents a change to a content type.

System.Object
  Microsoft.SharePoint.SPChange
    Microsoft.SharePoint.SPChangeContentType

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPChangeContentType : SPChange

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.

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();
      }
   }
}

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2016 Microsoft