Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

SPModerationInformation class

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)
[SubsetCallableTypeAttribute]
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.

NoteNote

For information about how to use Language-Integrated Query (LINQ) queries to retrieve list items in SharePoint Foundation, see Managing Data with LINQ to SharePoint.

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 Disposing 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.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.