none
SPUser "User cannot be found." error

    Question

  • 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

Answers

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.
    http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.ensureuser.aspx

    I wrote a blogpost about this in the context of assigning permissions to the user on a specific web:
    http://www.sharepointblogs.com/mirjam/archive/2007/12/20/using-spweb-ensureuser-loginname-to-add-a-new-spuser-to-a-web.aspx


    Mirjam --http://www.sharepointblogs.com/mirjam
    Wednesday, May 20, 2009 10:36 PM
  • you can also try

    web.SiteUsers["login id"]  
    http://mykbdump.blogspot.com/
    Thursday, May 21, 2009 2:26 AM
  • did that work or you still facing issue
    http://mykbdump.blogspot.com/
    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();
                }
                Context.Load(Context.Site);
                Context.Load(Context.Site.RootWeb);
                Context.Load(Context.Site.RootWeb.SiteUsers);
                Context.ExecuteQuery();
                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);
                            //Context.Site.RootWeb.SiteUsers.AddUser(user);
                            Context.Site.RootWeb.SiteUsers.AddUser(user);
                    }
                }

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


    kmk

    Saturday, September 16, 2017 9:59 AM