locked
How to determine a date when user became a member of sharepoint group? RRS feed

  • 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
    Peter
    Saturday, 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

    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

    Monday, February 8, 2010 3:18 AM
  • Hi

    I didnot get it properly excuse me for that.

    what i m searching for is, say i have a sharepoint group group1 and it has 3 users user1, user2, user3. what i trying to find is that when user1 or user2 or user3 is added to group1.

    Please write step by step code it will be helpfull for me.

    Arvind

    Friday, August 3, 2012 7:10 AM