Compartir a través de


SPChange Class

Represents a change that has been made to objects or metadata within an item, list, Web site, or site collection scope, or a security policy change at the Web application scope that has been recorded in the Windows SharePoint Services change log.

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.SPChange
    

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

Syntax

<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel := True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel := True)> _
Public Class SPChange

Dim instance As SPChange
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public class SPChange

Remarks

The Windows SharePoint Services change log does not record changes to global administrative settings, binary deployment, Web Parts and safe controls, or changes to the configuration of a site, site collection, content database, or virtual server. An SPChange object contains information about the type of change, as represented by the SPChangeType enumeration, and about the scope of the change, which can be a list, site, site collection, or content database.

Use the GetChanges method of the SPList, SPWeb, SPSite, or SPContentDatabase object to return the collection of changes that have occurred within the given scope. Use an indexer to return a single item from the collection. For example, if the collection is assigned to a variable named collChanges, use collChanges[index] in C# or collChanges(index) in Visual Basic, where index is either the index number of the item in the collection or a string containing the incoming URL of the request.

The security requirements for calling each of the SPChange properties are shown in the following table.

Object

Required right

SPList

Read list

SPSite

Global read account

SPVirtualServer

Global read account

Examples

The following code example displays the names of lists in which items within a Web site have changed.

[C#]

SPSite oSiteCollection = SPContext.Current.Site;
using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
{
    SPListCollection collLists = oWebsite.Lists;

    SPRegionalSettings oRegionSettings = oWebsite.RegionalSettings;
    SPTimeZone oTimeZone = oRegionSettings.TimeZone;

    SPChangeQuery oQuery = new SPChangeQuery(true, true);
    SPChangeCollection collChanges = oWebsite.GetChanges(oQuery);

    foreach (SPChange oChange in collChanges)
    {
        switch (oChange.GetType().ToString())
        {
        case "Microsoft.SharePoint.SPChangeItem":
            SPChangeItem oChangedItem = (SPChangeItem)oChange;
            try
            {
                Response.Write(collLists[oChangedItem.ListId].Title + 
                " == " +
                collLists[oChangedItem.ListId].GetItemByUniqueId(oChangedItem.UniqueId).Name 
                + " == " + oTimeZone.UTCToLocalTime(oChangedItem.Time)
                + " == " + oChangedItem.ChangeType + "<BR>");
            }
            catch
            {
                Response.Write("The object to which item " + 
                oChangedItem.UniqueId + 
                " belongs does not exist.<BR>");
            }
        break;
        }
    }
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Best Practices: Using Disposable Windows SharePoint Services Objects.

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.

See Also

Reference

SPChange Members

Microsoft.SharePoint Namespace

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.SPChange
    Microsoft.SharePoint.SPChangeAlert
    Microsoft.SharePoint.SPChangeContentType
    Microsoft.SharePoint.SPChangeField
    Microsoft.SharePoint.SPChangeFile
    Microsoft.SharePoint.SPChangeFolder
    Microsoft.SharePoint.SPChangeGroup
    Microsoft.SharePoint.SPChangeItem
    Microsoft.SharePoint.SPChangeList
    Microsoft.SharePoint.SPChangeSecurityPolicy
    Microsoft.SharePoint.SPChangeSite
    Microsoft.SharePoint.SPChangeUser
    Microsoft.SharePoint.SPChangeView
    Microsoft.SharePoint.SPChangeWeb