Share via


SPModerationInformation.Comment Property

Gets or sets a comment that addresses why the item was approved or rejected.

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

Syntax

'Declaration
Public Property Comment As String
    Get
    Set
'Usage
Dim instance As SPModerationInformation
Dim value As String

value = instance.Comment

instance.Comment = value
public string Comment { get; set; }

Property Value

Type: System.String
A string that contains the comment.

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 location of all approved items and the comment made by the approver.

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.Approved Then

                        Console.WriteLine((site.Url + "/" + _
                            docLibItem.File.Url + "/t" + _
                            docLibItem.ModerationInformation.Comment))

                    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.Approved)
                        {
                            Console.WriteLine(oWebsite.Url + "/" +
                            oListItem.File.Url + "/t" +
                            oListItem.ModerationInformation.Comment);
                        }
                    }
                }
            }
        }
        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