EnsureUser using email address in SharePoint client object model

15,235

You could resolve user by email address using Utility.ResolvePrincipal method, for example:

var result = Microsoft.SharePoint.Client.Utilities.Utility.ResolvePrincipal(ctx, ctx.Web, emailAddress,Microsoft.SharePoint.Client.Utilities.PrincipalType.User,Microsoft.SharePoint.Client.Utilities.PrincipalSource.All, null, true);
ctx.ExecuteQuery();
if (result != null)
{
    var user = ctx.Web.EnsureUser(result.Value.LoginName);
    ctx.Load(user);
    ctx.ExecuteQuery();    
} 

References

Get user identity and properties in SharePoint 2013

Share:
15,235
Page F.P.T
Author by

Page F.P.T

Updated on June 26, 2022

Comments

  • Page F.P.T
    Page F.P.T almost 2 years

    I need to update a FieldUserValue field in sharepoint 2013. i am only given an email address data. I can't user EnsureUser since it only accepts the logonName. i used the FromUser method but it gives me an error that says "the user does not exist or is not unique"

    FieldUserValue user = FieldUserValue.FromUser(email);
    

    it worked when i tried using my email address but when i use the email addresses in my data it results in an error. how do i fix the issue?