Answered by:
How to determine a date when user became a member of sharepoint group?

Question
-
Hi,
I would like to ask , how can I programatically get a date when user became a member of certain group. Is there a simple way how to get this date from SPUser or SPGroup classes (e.g is this information stored in m_arrMembersData object array of SPGroup class? - if yes, is there a wrappper/class capable to read this dates from m_arrMembersData array in strongly typed way?) or do I have to use SPAudit class?
Thanks
PeterSaturday, February 6, 2010 8:47 AM
Answers
-
Hi, Peter
I’m afraid it is not a good idea to tough SharePoint database.
I would recommend use SPAudit class, after you enable the Editing users and permissions audit, it can record all the user/group action log, like the simple sample below:
-------------------------------------------------------------------------------------------------------------
using (SPSite site = new SPSite("url"))
{
SPAuditQuery wssQuery;
SPAuditEntryCollection auditCol;
wssQuery = new SPAuditQuery(site);
wssQuery.AddEventRestriction(SPAuditEventType.SecGroupMemberAdd);
// SecGroupMemberAdd: Addition of a new member to a group that is associated with a SharePoint site collection
//Also some Enum type for group:
//SecGroupCreate/SecGroupDelete/SecGroupMemberAdd/SecGroupMemberDel
auditCol = site.Audit.GetEntries(wssQuery);
foreach (SPAuditEntry entry in auditCol)
{
//Execute send mail action here
}
}
-------------------------------------------------------------------------------------------------------------
Hope this can help.
Best Regards,
-Aaron
- Marked as answer by Aaron Han - MSFT Friday, February 12, 2010 9:47 AM
Monday, February 8, 2010 3:18 AM
All replies
-
Hi,I think currently in groups when user is added is not captured. In Content Database there are 3 columns under GroupMembership table. i.e SiteId, GroupId and MemberId.So in this case you need to check another work around. In other case it can be possible as ,Create another list . having columns Groupid,memberid and dateofJoining. Datatype of keep as int with no decimal. When ever you add user programmatically in any group Add entry in this table with values groupid,memberid and current date. And you can create wrapper class with joining date as a property in your class.Regards,Milan C.Saturday, February 6, 2010 12:18 PM
-
Hi, Peter
I’m afraid it is not a good idea to tough SharePoint database.
I would recommend use SPAudit class, after you enable the Editing users and permissions audit, it can record all the user/group action log, like the simple sample below:
-------------------------------------------------------------------------------------------------------------
using (SPSite site = new SPSite("url"))
{
SPAuditQuery wssQuery;
SPAuditEntryCollection auditCol;
wssQuery = new SPAuditQuery(site);
wssQuery.AddEventRestriction(SPAuditEventType.SecGroupMemberAdd);
// SecGroupMemberAdd: Addition of a new member to a group that is associated with a SharePoint site collection
//Also some Enum type for group:
//SecGroupCreate/SecGroupDelete/SecGroupMemberAdd/SecGroupMemberDel
auditCol = site.Audit.GetEntries(wssQuery);
foreach (SPAuditEntry entry in auditCol)
{
//Execute send mail action here
}
}
-------------------------------------------------------------------------------------------------------------
Hope this can help.
Best Regards,
-Aaron
- Marked as answer by Aaron Han - MSFT Friday, February 12, 2010 9:47 AM
Monday, February 8, 2010 3:18 AM -
Friday, August 3, 2012 7:10 AM