SPUser "User cannot be found." error


  • I am trying to update a SharePoint list column (People or Group) using C# code. NT AUTHORITY\authenticated users have been granted contribute permission at site collection, site, and list level. When program tries to find user by giving login id from web.AllUsers["login id"], it always throw SPException "User cannot be found". Any idea why it has been acting like that.
    Thursday, April 30, 2009 7:03 PM


All replies

  • Hi,

    Try using the EnsureUser() function of the SPWeb object.

    SPWeb web = SPContext.Current.Web;
    SPUser user = web.EnsureUser(@"domain\username");

    This will add the user to the web if it wasn't already available on the web.

    I wrote a blogpost about this in the context of assigning permissions to the user on a specific web:

    Mirjam --
    Wednesday, May 20, 2009 10:36 PM
  • you can also try

    web.SiteUsers["login id"]
    Thursday, May 21, 2009 2:26 AM
  • did that work or you still facing issue
    Monday, May 25, 2009 9:59 AM
  • Hi me too facing same issue please kindly help me below issue.

     private void button10_Click(object sender, EventArgs e)
                string adduser = string.Empty;
                adduser = textBox4.Text.Trim(); // input is textbox 
                //string authorized = null;
                string domain = System.Environment.UserDomainName;
                if (Context == null)
                    Context = Get_Context();
                foreach (var scUser in Context.Site.RootWeb.SiteUsers)
                    if (scUser.IsSiteAdmin)
                        User user = Web.EnsureUser(@"nes\adduser");// here iam getting error

                            // Context.Site.RootWeb.SiteUsers.AddUser()
                            // Context.Site.RootWeb.SiteUsers.AddUser(scUser.Id);

    please help me , i just want to add user as a site collection administrator.


    Saturday, September 16, 2017 9:59 AM