Sharepoint - How do I get SPUser Object?
Try this
SPUserCollection users=web.SiteUsers;
SPUser user=users.GetByID(31);
SPweb.User return only users who are directly set as user on the web, if someone have access to web because he is in the particular group, this user cannot be found. SPweb.SiteUsers return all users
Try any of the below:
web.EnsureUser(@"domain\loginname");//This will add user to site if not already added.
//Best to use this if you have the login name and
//user is already added.
web.SiteUsers.GetByID(31); //This will get you the user by id.