2

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!

Ashton
  • 1,265
  • 14
  • 23

2 Answers2

4

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);
Yevgeniy.Chernobrivets
  • 3,194
  • 2
  • 12
  • 14
  • Thanks Yevgeniy - I think the SiteUsers cannot be used with client object model. [link]http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.siteusers.aspx – Ashton Feb 06 '14 at 20:31
  • Hm, which version of SharePoint are you using? Seems like SharePoint 2013 has this property but SharePoint 2010 does not. Check here http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.web_members(v=office.15).aspx – Yevgeniy.Chernobrivets Feb 06 '14 at 20:33
  • Cool stuff! :) This works perfectly. I think my organization will upgrade to SP2013 sometime this year - not just yet. Thanks a lot Yevgeniy!! :) – Ashton Feb 06 '14 at 21:21
  • hi @Yevgeniy.Chernobrivets, what if the display name of two employees remains the same? for example: "john smith", and "john, smith", but with their email is having johns1@domain.com and johns2@domain.com, so, there will be a conflict in identifying the person/email of by sharepoint? how to handle this situation – samolpp2 May 30 '19 at 06:40
0
        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);