Wednesday, April 15, 2009

Making a custom entry in sharepoint audit logs

Scenario:
While working on some audit requirements, I wanted to write an entry in Audit Log of sharepoint.

Solution:
SharePoint API always have something for its developer :-)

Code:

int ItemId = 1; 
SPWeb web = SPContext.Current.Web;
SPList list = web.Lists["Shared Documents"];
SPListItem item = list.Items.GetItemById(Convert.ToInt32(ItemId));
item.Audit.WriteAuditEvent(SPAuditEventType.Custom,
"CustomAudit", // SoureName
"File Downloaded" // Any arbitrary XML data
);

0 comments: