Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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))
{
    context.Execute(delegate
    {
        SPList spList = context.Web.Lists[yourListId];
        SPListItem spItem = spList.GetItemById(yourItemId);

        SPAuditQuery auditQuery = new SPAuditQuery(context.Site);
        auditQuery.RestrictToListItem(spItem);

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

     });   
}

return auditEntries;
share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

http://www.codeproject.com/Articles/431342/Auditing-A-Built-in-Feature-of-SharePoint

SPAudit and its members

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spaudit.aspx

members

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spaudit_members.aspx

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

SPAuditQuery wssQuery = new SPAuditQuery(siteCollection);
wssQuery.RestrictToListItem(item);
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);
wssQuery.RestrictToUser(web.CurrentUser.ID);
wssQuery.AddEventRestriction(SPAuditEventType.View);
wssQuery.RestrictToList(SPContext.Current.List);

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

http://stackoverflow.com/questions/5158411/how-could-i-get-access-to-the-audit-log-for-non-admin-users

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

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spauditquery.aspx

EDIT

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);
oAuditQuery.RestrictToListItem(item);
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 :)

http://msdn.microsoft.com/en-us/library/ms457256.aspx

hope it helps :)

share|improve this answer
1  
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
show 1 more comment

Your Answer

 
discard

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.