SPAudit.DeleteEntries Method
Deletes all audit events that occurred before the specified date and time from the SharePoint database.
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: No
Syntax
'Declaration
Public Function DeleteEntries ( _
deleteEndDate As DateTime _
) As Integer
'Usage
Dim instance As SPAudit
Dim deleteEndDate As DateTime
Dim returnValue As Integer
returnValue = instance.DeleteEntries(deleteEndDate)
public int DeleteEntries(
DateTime deleteEndDate
)
Parameters
deleteEndDate
Type: System.DateTimeA DateTime representing the earliest date and time for which you want to preserve audit data.
Return Value
Type: System.Int32
An Int32 that represents the number of audit entries that were deleted.
Exceptions
Exception | Condition |
---|---|
UnauthorizedAccessException | The calling code is in the context of a user who is not a site administrator. |
SPException | The parent object that has this SPAudit object as the value of its Audit property is not an SPSite object. |
Remarks
Warning
You may call object.Audit.DeleteEntries only when object is an SPSite object.
The deletion of audit entries is itself an audited event. A call to DeleteEntries creates an entry, and the method cannot delete the entry that it makes, so at least that one entry always exists in the database even if you attempt to delete all entries.
In Windows SharePoint Services 3.0, to delete all entries (except the entry described in the preceding paragraph) you cannot simply specify the current moment for deleteEndDate with Now. You must designate a future time. We recommend the following code, where mySiteCollection is a reference to an SPSite object.
mySiteCollection.Audit.DeleteEntries(DateTime.Now.AddMilliseconds(1));
mySiteCollection.Audit.DeleteEntries(Date.Now.AddMilliseconds(1))
See Also
Reference
Microsoft.SharePoint Namespace