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;

1 Answer 1


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 :)

  • 2
    This is a very nice answer, I didn't even know what it was. But does it answer the question, targeting JavaScript?
    – eirikb
    Commented Sep 15, 2012 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 Jafer
    Commented Sep 15, 2012 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
    Commented Sep 15, 2012 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 Jafer
    Commented Sep 15, 2012 at 10:30
  • ok have changed it to add the webservice part just incase :)
    – Ali Jafer
    Commented Sep 15, 2012 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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