To pull the user information, you first have to convert the field into a SPFieldUser object, and then create a collection of the SPFieldUserValueCollection.
Then, loop through the collection and pull the Email property of the SPFieldUserValue.
code sample:
———————————————————————-
string sFieldNameTo = “BU Legal To Email”;
string sFieldNameCC = “BU Legal CC Email”;
//Add To and CC based on multiple user field
if (workflowProperties.Item[sFieldNameTo] != null)
{
SPFieldUser UsersColumn = (SPFieldUser)workflowProperties.Item.Fields.GetField(sFieldNameTo);
SPFieldUserValueCollection Users = (SPFieldUserValueCollection)UsersColumn.GetFieldValue(workflowProperties.Item[sFieldNameTo].ToString());
foreach (SPFieldUserValue fieldUser in Users)
{
if (fieldUser.User.Email != null && fieldUser.User.Email != string.Empty)
{
mail.To.Add(fieldUser.User.Email);
}//
}//
}//
if (workflowProperties.Item[sFieldNameCC] != null)
{
SPFieldUser UsersColumn = (SPFieldUser)workflowProperties.Item.Fields.GetField(sFieldNameCC);
SPFieldUserValueCollection Users = (SPFieldUserValueCollection)UsersColumn.GetFieldValue(workflowProperties.Item[sFieldNameCC].ToString());
foreach (SPFieldUserValue fieldUser in Users)
{
if (fieldUser.User.Email != null && fieldUser.User.Email != string.Empty)
{
mail.CC.Add(fieldUser.User.Email);
}//
}//
}//
Updated 5/11/16
For CSOM use this:
foreach (FieldUserValue userValue in item[“MultiUser”]as FieldUserValue[])
{
}//
[…] http://surfpointtech.com/2011/09/12/how-to-pull-the-email-addresses-from-a-sharepoint-user-field-all… […]