Answered Get All members in given sharepoint target audience group

  • Sunday, August 05, 2012 10:09 AM
     
     

    HI i have a announcement web part in root site and when admin put new announcement in root site i am copying  the data to all mysites using event listener.

    i have 3 target audience groups and i need to get members in each group and update their list separately.

    for updating i need to get the all members of the audience group.    

    what i really need is get the all members in given target audience  group


    regards Manoj Handapangoda

All Replies

  • Sunday, August 05, 2012 11:37 AM
     
     

    Hi,

    I don't understand really your needs... But if you want get the all members of the audience Group :

    use SPGroup.Users (cf http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spgroup.users.aspx)

    NicoBzh

  • Monday, August 06, 2012 4:15 AM
     
     

    Hi,Hioi

    I don't understHi and really your needs... But if you want get the all members of the audience Group :

    use SPGroup.Users (cf http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spgroup.users.aspx)

    NicoBzh

    Hi I have created audience group called "SIND" and it has 12 members. so i need to retrieve those user information.




    regards Manoj Handapangoda



  • Monday, August 06, 2012 6:08 AM
     
     Answered Has Code

    Hi,

    So use SPGroup.Users and ProfileManage to get users profile

    SPGroup group = Web.SiteGroups["SIND"];
    UserProfileManager profileManager = new UserProfileManager();
    foreach (SPUser user in group.Users)
    {
    UserProfile userProfile = profileManager.GetUserProfile(user.LoginName);
     var myProperty = userProfile ["myProperty"].Value ;
    }
    
    NicoBzh
  • Monday, August 06, 2012 6:29 AM
     
     Answered Has Code
    bool reachedMax;
    SPPrincipalInfo[] principals = SPUtility.GetPrincipalsInGroup(SPWeb, groupName, 500, out reachedMax);
    foreach (SPPrincipalInfo principal in principals)
    {
       //your code
    }
    

  • Monday, August 06, 2012 7:57 AM
     
     Answered Has Code

    Hello!

    using (SPSite site = new SPSite("http://localhost"))
    {
      var context = ServerContext.GetContext(site);
      var audienceManager = new AudienceManager(context);
      foreach (Audience audience in audienceManager.Audiences)
      {
        var people = audience.GetMembership();
        if (people != null)
        {
          //Your actions
        }       
    }

    or for specific audience:

    var people = audienceManager.Audiences["My audience"].GetMembership(); 

    My contributions: SharePoint 2010 Solution Installer



    • Edited by Aviw_ Monday, August 06, 2012 8:03 AM
    • Marked As Answer by Lhan HanModerator Thursday, August 16, 2012 3:14 AM
    •