Display User Activites in a Sharepoint Web Part

Enable Audit log for the site collection. Note this works only on site collection , if you would like to use for the entire farm then you have to run thro all the site collections in the web app, and all web app in the farm.


                using (SPSite site = new SPSite("site url"))
                    using (SPWeb web = site.OpenWeb())
                        SPUserCollection userCol= web.AllUsers;
                        SPUser user = web.AllUsers["\\"];
                        int userid = user.ID;
                        SPAuditQuery qry = new SPAuditQuery(site);
                        SPAuditEntryCollection auditCol = site.Audit.GetEntries(qry);
                        foreach (SPAuditEntry entry in auditCol)
                          //  writetolog("Message");  this is your log info


Leave a Reply

Your email address will not be published. Required fields are marked *