SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried to update Person column with C#. NT AUTHORITY\authenticated users in the site have read permission at site site level. Sometimes when the code try to find user by login id from web.AllUsers["login id"] it throws an SPException "User cannot be found". How can I fix this mess?

share|improve this question
up vote 2 down vote accepted

Adding all authenticated users does not mean they are getting to the site. Yes, they have permission to site but if you check the User Information List of the site, they cannot be found there.

When you call web.AllUsers, it checks in the user information list. Since the user is not there, it can cause error. There are scenarios where SharePoint put into this list by itself.

  1. Authenticated user logs into site.
  2. Add user through OOTB people picker.

The solution to this is using the web.EnsureUser(@"domain\username"). This will first check whether the user is there in the User Information List and if not, the user will be added to the list and then return the SPUser object.

share|improve this answer
I am also adding this through people picker. – Angelo Perez Aug 24 '14 at 10:22
The Out Of The Box people picker is different to the one that you are using. Also in that forms, the implementations are written by SharePoint Team. So they should have added it. – Malin De Silva Aug 24 '14 at 10:25

Ensure that the user you are trying to add exist in the web site. You can make use of EnsureUser() function of the SPWeb object.

You may write your code as:

SPWeb spWeb = SPContext.Current.Web;
SPUser spUser = spWeb.EnsureUser(@"DOMAIN\username");

On MSDN article you can learn more about EnsureUser() function.

Hope this helps.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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