SPModerationInformation.Comment Property
Gets or sets a comment that addresses why the item was approved or rejected.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
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. |
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 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. |
Note