Reputation: 1365
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!
Upvotes: 2
Views: 9217
Reputation: 1
FieldUserValue [] fTo = oListItem["People picker field name"] as FieldUserValue[];
var userTo = clientContext.Web.SiteUsers.GetById(fTo[0].LookupId);
clientContext.Load(userTo);
clientContext.ExecuteQuery();
headers.To.Add(userTo.Email);
Upvotes: 0
Reputation: 3194
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);
Upvotes: 4