0

I need to ensure the user from list people picker column using csom.

Scenario: we have one user in AD and i have added one list item in 2017. The user was being added to the site at that time and user id created was 150.

Now I am retrieving the list item using csom, using below code.

userDetails = context.Web.GetUserById(150);

But this line throwing the exception that 150 user is not found.

when i checked the person from the site users, she is getting different id (33254).

How this was came i am unable to understand. There might be many list items facing the same issue.

I can not update users of each item.

can I check/ensure if user id is changed in the site, then get the user from updated id using csom??

Thanks for any help.

1

1 Answer 1

1

Once the user is ensured in web means the id will be same at the entire sitecollection. Use the following code to check the id of the user. If you know the login name of user you can use the following method:

var loginName = "[email protected]";

User user = Context.Web.EnsureUser(loginName);

Context.Load(user);

Context.ExecuteQuery();

1
  • I am able to get only display name from people picker user value. it is ensuring user from above code. But I believe Display name can not be unique. so, i need to work on getting user login name for ensuring. do you have any code to get Login name? Commented Aug 14, 2018 at 11:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.