Question

Can anyone try getting the username and email of all the users in a Array of the People picker control in SharePoint 2010?

If so can you provide me a Method this?

The method should have parameters like (sharepointgroupname,sharepoint user)

I have tried Like This. But it returns only one user name and email address from people picker control. I want to retrieve for multiple users Sharepoint group and Active Directory group. Please help me.

 private void GetNameAndEmailFromPeoplePicker(SPListItem mySourceListItem, out String PeoplePicker, out String CCPeoplePicker, out String UserName)
        {
            PeoplePicker = "";
            CCPeoplePicker = "";
            UserName = "";
            try
            {

                SPFieldUserValueCollection Users = new SPFieldUserValueCollection(mySiteWeb, Convert.ToString(mySourceListItem["Point of Contact"]));
                foreach (SPFieldUserValue User in Users)
                {
                    UserName = User.User.Name;
                    PeoplePicker = User.User.Email;
                }
                SPFieldUserValueCollection BCCUsers = new SPFieldUserValueCollection(mySiteWeb, Convert.ToString(mySourceListItem["Backup Point of Contact"]));
                foreach (SPFieldUserValue BCCUser in BCCUsers)
                {
                    CCPeoplePicker = BCCUser.User.Email;
                }
            }

            catch (Exception ex)
            {
                UlsLogs.LogErrorInULS(ex.InnerException.ToString(), TraceSeverity.High);
            }
        }

No correct solution

OTHER TIPS

Get USer Names and Emails from a Sharepoint People Picker.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;

namespace GETEMAILSFROMPEOPLEPICKER
{
    public static class SPFieldUserValueCollectionExtensions
   {     
       public static IEnumerable<string> GetAllEmails(this SPFieldUserValueCollection collection, SPWeb web) 
       {
           //System.Diagnostics.Debugger.Break();

           var emails = new HashSet<string>();

           foreach (var item in collection)  
           {        
               if (item.User == null)  
               {          
                   try  
                   {   
                       // is it a SharePoint group?   
                       var group = web.SiteGroups.GetByID(item.LookupId); 
                       emails.AddEmailsFromSPGroup(group);

                   }           
                   catch    
                   {  

                      // ad group  
                       var group = web.EnsureUser(item.LookupValue); 
                       emails.AddIfNotNull(group.Email);   
                   }          
               }            
               else           
               {               
                   emails.AddIfNotNull(item.User.Email);  
               }      
           }         
           return emails;  
       }
       private static void AddEmailsFromSPGroup(this HashSet<string> emails,SPGroup group)  
       {       
           if (!string.IsNullOrEmpty(group.DistributionGroupEmail))   
           {        
               emails.Add(group.DistributionGroupEmail); 
           }         
           else      
           {         
               foreach (SPUser user in group.Users)    
               {    
                   emails.AddIfNotNull(user.Email);    
               }      
           }    
       }      

       private static void AddIfNotNull(this HashSet<string> set, string s)   
       {
           if(!string.IsNullOrEmpty(s)) 
           {           
               set.Add(s); 
           }     
       }

       public static IEnumerable<string> GetAllLoginNames(this SPFieldUserValueCollection collection, SPWeb web)
       {
            var usernames = new HashSet<string>();

            foreach (var item in collection)
            {
                if (item.User == null)
                {
                    try
                    {
                        // is it a SharePoint group?   
                        var group = web.SiteGroups.GetByID(item.LookupId);

                        usernames.UserNamesFromSPGroup(group);
                    }
                    catch
                    {

                        // ad group  
                        var group = web.EnsureUser(item.LookupValue);
                        usernames.IfNotNull(group.Name);
                    }
                }
                else
                {
                    usernames.AddIfNotNull(item.User.Name);
                }
            }   
            return usernames;

       }

       private static void UserNamesFromSPGroup(this HashSet<string> usernames, SPGroup group)
       {
           if (!string.IsNullOrEmpty(group.DistributionGroupEmail))
           {
               usernames.Add(group.DistributionGroupAlias);
           }
           else
           {
               foreach (SPUser user in group.Users)
               {
                   usernames.AddIfNotNull(user.Name);
               }
           }
       }

       private static void IfNotNull(this HashSet<string> set, string s)
       {
           if (!string.IsNullOrEmpty(s))
           {
               set.Add(s);
           }
       }
   } 

}

I'm not sure to understand your question... and in which language do you want to use it?

With JavaScript I use this method to do the same thing as the People Picker...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top