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.

  • EnsureUser is not using User Profile Service, but the authentication provider for your web application, which most likely is AD. Does the user exist in AD? – Per Jakobsen Mar 26 '12 at 6:53
  • Ya, the user does exist in the AD. – Mansi Desai Mar 26 '12 at 6:55
  • Quick suggestion: could you confirm if the working user are already available on the site and the not-working ones aren't? To be clearer: you may want to confirm if the method isn't working for all user that must be first-added to the web site or only for some specific users. – BlueSoul Mar 26 '12 at 7:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.