I want to insert the user account for each user in a list column. As the list column is of type Person or Group, I need to convert the string type value to the person or group type. I have used the following function to convert the string value to person or group type :
public SPFieldUserValue convertToPersonorGroup(string userid,SPWeb web)
{
if(userid != null)
{
SPUser requireduser = web.EnsureUser(userid);
SPFieldUserValue uservalue = new SPFieldUserValue(web, requireduser.ID,requireduser.LoginName);
return uservalue;
}
return null;
}
This function works fine for most of the user account names but in one of the account name it throws "The specified user indusa\ezend could not be found." exception.
I have also checked in the User Profile Service and this user exists there.but still I get this exception. I am not able to figure out the cause of the error. Kindly help.
Thanks in advance.