Поделиться через


SPModerationInformation Class

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

Inheritance Hierarchy

System.Object
  Microsoft.SharePoint.SPModerationInformation

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

Syntax

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

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

Examples

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.

Dim siteCollection As New SPSite("http://localhost")
Dim subSites As SPWebCollection = siteCollection.AllWebs
Dim site As SPWeb

For Each site In  subSites

    Dim lists As SPListCollection = site.Lists
    Dim list As SPList

    For Each list In  lists

        If list.BaseType = SPBaseType.DocumentLibrary Then

            Dim docLibrary As SPDocumentLibrary = 
                CType(list, SPDocumentLibrary)

            If Not docLibrary.IsCatalog AndAlso 
                    docLibrary.EnableModeration = True Then

                Dim allItemsQuery As New SPQuery()

                allItemsQuery.ViewAttributes = 
                    "ModerationType='Moderator'"

                Dim docLibItems As SPListItemCollection = 
                    docLibrary.GetItems(allItemsQuery)
                Dim docLibItem As SPListItem

                For Each docLibItem In  docLibItems

                    If docLibItem.ModerationInformation.Status = 
                            SPModerationStatusType.Pending Then

                        Console.WriteLine(site.Url + "/" + 
                            docLibItem.File.Url)

                    End If
                Next docLibItem
            End If
        End If
    Next list
Next site
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();
    }
}

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

SPModerationInformation Members

Microsoft.SharePoint Namespace