0

I have a custom webpart in which I get the SPUser object from email address, see the code below. It was working fine for like an year now , but since yesterday it gives a

"User cannot be found"

error. There was no change made in the code or anywhere else. And I checked in the User Information List whether those email addresses exists and they do. I do understand what is causing this error. Any suggestion on were to look is appreciated.

Here is the line that's causing problem now:

spUser = spWeb.SiteUsers.GetByEmail(txtEmail.Text);

Update

I also tried checking through powershell by the following method. In this case I am getting some of the users correctly. but for some other users email addresses I tried, it returns the same

"user cannot be found" exception.

$user = $web.Users.GetByEmail("email@domain.com")
  • Can you please check the User Exists in Active Directory ? User deleted is not synced with UserInformationList instantly – Akarsh Gupta Jun 16 '16 at 11:49
  • @AkarshGupta ... The users are both in AD and in the user info list. And both places have the email address set. – mallu coder Jun 16 '16 at 12:36
  • 1
    For your Powershell, to make sure you're comparing apples to apples, make sure you access $web.SiteUsers instead of $web.Users – Thriggle Jun 16 '16 at 20:20
  • @Thriggle Thanks for that tip but that doesnt solve my issue. – mallu coder Jun 17 '16 at 11:19
0

One option may be to replace spWeb.SiteUsers.GetByEmail with spWeb.EnsureUser.

Even though the documentation indicates that EnsureUser accepts a user's domain\username as a parameter, in practice I've found that an email address works as well, although this may be dependent on your environment's configuration.

-1

kindly try below.

spUser = spWeb.AllUsers.GetByEmail(txtEmail.Text);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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