Explore the Experience in SharePoint 2013

Monday, December 1, 2014

How to get multiple users from Sharepoint list through programatically (C#).

No comments
Hi Guys ,

Thanks for visiting to my blog .

Background or scenario:
    Some times we come across a situation where in we have to get multiple users data  from  SharePoint list and use the details as per the requirment. (My requirment is getting users mail ids and send them mail at one shot).


Note : If people picker selects multiple users then only we can use the below code .

we can get the users data using C# server object model .

String  strCCEmail  =String.Empty();
 SPList  listObject=Spweb.Lists.TrygetList("Listname");
 SPFieldUser UsersColumn = (SPFieldUser)listObject.Fields.GetField("CoulmName");
 SPFieldUserValueCollection Users = (SPFieldUserValueCollection)UsersColumn.GetFieldValue(lstitemCollection[0]["CoulmName"].ToString());
   if (Users != null)
     {
                                     
     foreach (SPFieldUserValue user in Users)
            {
                        SPUser spUser = user.User;                  
                        if (spUser != null)                                             
                        strCCEmail = strCCEmail + ";" + spUser.Email;
                }                                                                         

          strCCEmail = strCCEmail.TrimStart(';');
                            
     }      





No comments :

Post a Comment