How to get email addres from PeoplePicker field using C# and Client Object model

Ashton picture Ashton · Feb 6, 2014 · Viewed 7.6k times · Source

I am using CAML to retrieve some sharepoint list items. On of the columns is a PeoplePicker control. How can I extract the email address from this column?

I know how to get the LookupValue and LookupID, but not the email.

FieldUserValue usvSM1 = i["Account"] as FieldUserValue;
Console.WriteLine(usvSM1.LookupValue);

Keep in mind that I'm programming against the client object model.

Thanks a lot!

Answer

Yevgeniy.Chernobrivets picture Yevgeniy.Chernobrivets · Feb 6, 2014

Try this:

var user = web.SiteUsers.GetById(usvSM1.LookupId);

context.Load(user);
context.ExecuteQuery();

Console.WriteLine(user.Email);

EDIT: Web.SiteUsers property is available only SharePoint 2013 client object model.

Second way you can try to get user:

var user = web.EnsureUser(usvSM1.LookupValue);

context.Load(user);
context.ExecuteQuery();

Console.WriteLine(user.Email);