Error: The specified user could not be found, when using EnsureUser RRS feed

  • Question

  • Hi,

    I am trying to use the below code, to assign value to peoplepicker. UsersLanId is in the format of "dir\Lan ID"

    if (UsersLanID != string.Empty)
    SPUser adminUser = oWeb.EnsureUser(UsersLanID);
    SPFieldUserValue userValue = new SPFieldUserValue(oWeb, adminUser.ID, adminUser.LoginName);
    requestItem["RequestAssignedTo"] = userValue;

    When the below line is hit

    oWeb.EnsureUser(UsersLanID); ,

    I am getting error as "The specified user could not be found".

    How to fix this?


    Monday, March 6, 2017 5:58 AM

All replies

  • Hi Venkatzeus,

    The EnsureUser parameter format is "Domainname\UserLogoname", if the parameter is valid, then the exception could throw when the user not existed in the website.

    I suggest you can check if the user existed in Active Directory, more information about this method:

    SPWeb.EnsureUser method


    Best Regards

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    Tuesday, March 7, 2017 2:46 AM