SPAudit.GetEntries Method (SPAuditQuery)

Gets a collection of SPAuditEntry objects from the audit data stored in the SharePoint database that match the specified query.

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

Syntax

'Declaration
Public Function GetEntries ( _
    query As SPAuditQuery _
) As SPAuditEntryCollection
'Usage
Dim instance As SPAudit
Dim query As SPAuditQuery
Dim returnValue As SPAuditEntryCollection

returnValue = instance.GetEntries(query)
public SPAuditEntryCollection GetEntries(
    SPAuditQuery query
)

Parameters

Return Value

Type: Microsoft.SharePoint.SPAuditEntryCollection
An SPAuditEntryCollection that holds the requested SPAuditEntry items.

Exceptions

Exception Condition
UnauthorizedAccessException

The calling code is in the context of a user who is not a site administrator.

ArgumentException

query is a null reference (Nothing in Visual Basic).

Remarks

For a simpler method that does not require you to create an SPAuditQuery object, see GetEntries.

Examples

The following example (from Item-Level Auditing with SharePoint Server 2007) shows this method in use.

SPSite oSiteCollection = (SPSite)properties.Feature.Parent;
SPAuditQuery oAuditQuery = new SPAuditQuery(oSiteCollection);
oAuditQuery.RestrictToListItem(item);
SPAuditEntryCollection collAuditEntries = oSiteCollection.Audit.GetEntries(oAuditQuery);

foreach (SPAuditEntry oAuditEntry in collAuditEntries) {
  // get info from audit log
}
Dim oSiteCollection As SPSite = CType(properties.Feature.Parent, SPSite)
Dim oAuditQuery As New SPAuditQuery(oSiteCollection)
oAuditQuery.RestrictToListItem(item)
Dim collAuditEntries As SPAuditEntryCollection = oSiteCollection.Audit.GetEntries(oAuditQuery)

For Each oAuditEntry As SPAuditEntry In collAuditEntries
  ' get info from audit log
Next oAuditEntry

See Also

Reference

SPAudit Class

SPAudit Members

GetEntries Overload

Microsoft.SharePoint Namespace

Other Resources

Item-Level Auditing with SharePoint Server 2007