Can I read from audit log, how many times item has been clicked? I know that I can do it using Server edition, but what about Foundation?
What I have done: Central Administration, I enabled Secure Store Service / "Audit log enabled"
I also installed https://auditlogsp.codeplex.com/ and I checked logs. However, it seems that Foundation do not save item openings?
I can read same log of course from database: WSS_Content.AuditData
My idea is get all items, which users have clicked most. Can anyone confirm, whether this possible?
I also tried using custom code, but some reason it return 0:
class MostViewedItems
{
public DataTable table = new DataTable();
public SPSite siteUrl;
public DataTable GetRecentlyViewedReports()
{
try
{
table.Columns.Add("ItemId", typeof(Guid));
table.Columns.Add("ItemName", typeof(string));
table.Columns.Add("ItemCount", typeof(int));
siteUrl = SPContext.Current.Site;
string url = siteUrl.Url;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(url))
{
foreach (SPWeb web in site.RootWeb.GetSubwebsForCurrentUser())
{
getRecentAuditlog(web, "Documents");
web.Dispose();
}
}
});
// TODO
}
}
public void getRecentAuditlog(SPWeb web, string lst)
{
try
{
SPList list = web.Lists.TryGetList(lst);
if (list != null)
{
SPAuditQuery spQuery = new SPAuditQuery(web.Site);
spQuery.RestrictToList(list);
spQuery.RestrictToUser(SPContext.Current.Web.CurrentUser.ID);
spQuery.AddEventRestriction(SPAuditEventType.View);
spQuery.SetRangeStart(DateTime.Today.AddDays(-30));
spQuery.SetRangeEnd(DateTime.Today.AddDays(1));
SPAuditEntryCollection auditCol = web.Site.Audit.GetEntries(spQuery);
// auditCol returns 0
}