Monday, June 22, 2009

Enable Audit settings for a Sharepoint List Programmatically

Share/Save/Bookmark

Sharepoint provides audit property for the objects that can be audited. Its pretty easy to turn on audit feature programmatically on any list/document library or a sitecolleciton by setting the values for the property. In the object model, for a SPList, SPListItem the audit property can be set on specific events so that it doesn’t generate huge data. Code as follows :

SPSite siteCollection = SPContext.Current.Site;
SPWeb site = siteCollection.RootWeb;
SPList docLib = site.Lists("DocLibName");
// Turn on auditing flags.
docLib.Audit.AuditFlags = SPAuditMaskType.View |
                          SPAuditMaskType.ChildDelete;
docLib.Audit.Update();

In the above example only view and delete events get audited, any more events to be audited can be added to audit flag separating Bitwise OR.

Auditing options:

SPAuditMaskType.CheckIn
SPAuditMaskType.CheckOut
SPAuditMaskType.ChildDelete
SPAuditMaskType.Copy
SPAuditMaskType.Delete
SPAuditMaskType.Move
SPAuditMaskType.ProfileChange
SPAuditMaskType.SchemaChange
SPAuditMaskType.Search
SPAuditMaskType.SecurityChange
SPAuditMaskType.Undelete
SPAuditMaskType.Update
SPAuditMaskType.View
SPAuditMaskType.Workflow

Subscribe

No comments:

Post a Comment