Share via


SPModerationInformation.Status Property

Gets or sets a value that specifies the content approval status for an item.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Property Status As SPModerationStatusType
    Get
    Set
'Usage
Dim instance As SPModerationInformation
Dim value As SPModerationStatusType

value = instance.Status

instance.Status = value
public SPModerationStatusType Status { get; set; }

Property Value

Type: Microsoft.SharePoint.SPModerationStatusType
An SPModerationStatusType value that specifies the status.

Examples

The following code example approves all the pending items on a site collection and returns the location of the approved item.

Note

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.

Dim siteCollection As New SPSite("https://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))
                        docLibItem.ModerationInformation.Comment = _
                            "Automatic Approval of items"
                        docLibItem.ModerationInformation.Status = _
                            SPModerationStatusType.Approved
                        docLibItem.Update()

                    End If
               Next docLibItem
           End If
       End If
   Next list
Next site 
using (SPSite oSiteCollection = new SPSite("https://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 oDocumentLibrary = (SPDocumentLibrary)oList;

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

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

                    SPListItemCollection collListItems =
                        oDocumentLibrary.GetItems(oQuery);

                    foreach (SPListItem oListItem in collListItems)
                    {
                        if (oListItem.ModerationInformation.Status ==
                            SPModerationStatusType.Pending)
                        {
                            Console.WriteLine(oWebsite.Url + "/" +
                                oListItem.File.Url);
                            oListItem.ModerationInformation.Comment =
                                "Automatic Approval of items";
                            oListItem.ModerationInformation.Status =
                                SPModerationStatusType.Approved;
                            oListItem.Update();
                        }
                    }
                }
            }
        }
        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 Disposing Objects.

See Also

Reference

SPModerationInformation Class

SPModerationInformation Members

Microsoft.SharePoint Namespace