Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

SPModerationInformation Class

Windows SharePoint Services 3

Provides information about the content approval status for an item in a list or a document library.

System.Object
  Microsoft.SharePoint.SPModerationInformation

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

[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel = true)]
public class SPModerationInformation

The following code example iterates through all the document libraries with content approval enabled on every site in the current site collection, and displays the URLs of all pending documents.

using (SPSite oSiteCollection = new SPSite("http://localhost"))
{
    SPWebCollection collWebsites = oSiteCollection.AllWebs;

    foreach (SPWeb oWebsite in collWebsites)
    {
       SPListCollection collLists = oWebsite.Lists;

       foreach (SPList oList in collLists)
       {
           if (oList.BaseType == SPBaseType.DocumentLibrary)
           {
               SPDocumentLibrary oDocLibrary = (SPDocumentLibrary)oList;

                if (!oDocLibrary.IsCatalog && oDocLibrary.EnableModeration == true)
                {
                    SPQuery oQuery = new SPQuery();

                    oQuery.ViewAttributes = "ModerationType='Moderator'";

                    SPListItemCollection collListItems = oDocLibrary.GetItems(oQuery);

                    foreach (SPListItem oListItem in collListItems)
                    {
                        if (oListItem.ModerationInformation.Status == SPModerationStatusType.Pending)
                        {
                            Console.WriteLine(oWebsite.Url + "/" + oListItem.File.Url);
                        }
                    }
                }
            }
        }
        oWebsite.Dispose();
    }
}
NoteNote

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.

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

Community Additions

ADD
Show:
© 2015 Microsoft