SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Or there's a SP2010 Built-in service to access Audit data?

[UPDATE] Quick awnser, No, there's no way to access the SPAuditQuery from the SP JavaScript Class Library.

At the end I end up using a WCF Service, using all the guidance provided by @almostSharepointMaster, pulling the SPAuditQuery from javascript, just don't forget to elevate the context when querying from a WCF Service

using (ElevatedContext context = new ElevatedContext(SPContext.Current.Web, SPContext.Current.Site))
        SPList spList = context.Web.Lists[yourListId];
        SPListItem spItem = spList.GetItemById(yourItemId);

        SPAuditQuery auditQuery = new SPAuditQuery(context.Site);

        SPAuditEntryCollection auditEntries = context.Site.Audit.GetEntries(auditQuery);


return auditEntries;
share|improve this question
up vote 2 down vote accepted

Its explained indepth here with images how to use SPAudit ;)

SPAudit and its members


This is taken from msdn that shows you how to access the log,

SPAuditQuery wssQuery = new SPAuditQuery(siteCollection);
SPAuditEntryCollection auditCol = site.Audit.GetEntries(wssQuery);

foreach (SPAuditEntry entry in auditCol) {
  // get info from audit log

This was taken from another thread posted below:

SPAuditQuery wssQuery = new SPAuditQuery(web.Site);

SPAuditEntryCollection auditCol;
auditCol = web.Site.Audit.GetEntries(wssQuery);

you could also use:

 SPAuditQuery wssQuery = 
  new SPAuditQuery(SPContext.Current.Site);

please also note that youll run into some restricons with amdmin right! as the last link states, take into condiseration the statment below from msdn also especialy the last part ;)

My solution to the restriction is using SPSecurity.RunwithElevatedPrivileges as a little work around :)

The fundamental scope of any query is always a site collection; but you can use the members of the class to restrict a query to particular date ranges, users, event types, lists, and list items.

This class is primarily used as a parameter to the GetEntries(SPAuditQuery) method.

You cannot use this class to query the SharePoint database for anything other than the records of audited events.

SPAutitQuery class


If you want to use a webservice you can by following the example, all you need to do is have this code:

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

foreach (SPAuditEntry oAuditEntry in collAuditEntries) {
  // get info from audit log

obviously have a return method that returns the results :)

hope it helps :)

share|improve this answer
This is a very nice answer, I didn't even know what it was. But does it answer the question, targeting JavaScript? – eirikb Sep 15 '12 at 10:06
well he did say "Or there's a SP2010 Built-in service to access Audit data?" so i would presume from that, that he would also want to know if there are any other methods available what i outlined above that I would think he should use! tbh I dont know if its even possible with Javascript as you will run into premission problems from client side let alone from server side – ali Sharepoint Sep 15 '12 at 10:20
I see. So not even with a Web service? I'll bump your answer, and if its not possible with JavaScript this is most likely the correct answer :) – eirikb Sep 15 '12 at 10:24
You can use a custom webservice. All the webservice would need to do is execute the GetEntries method and return the result, but youll get into the hassle of making a webservice lol – ali Sharepoint Sep 15 '12 at 10:30
ok have changed it to add the webservice part just incase :) – ali Sharepoint Sep 15 '12 at 10:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.