SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a people picker field in my custom web part and when the user fills the data and submits it i want this value to be populated in a share point list .following is the code i am using and this is giving me a error "The specified user not found" Can you please help me with this . Also i tested for other fields and those are populating without any error only this filed is giving me error..

SPWeb app = SPContext.Current.Web;
        SPList ListName = app.Lists["Communities Directory"];
        SPListItem ListItem = ListName.Items.Add();
        string[] UsersSeperated = pickAdministrators.CommaSeparatedAccounts.Split(',');
        SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();
        foreach (string UserSeperated in UsersSeperated)

            SPUser User = app.SiteUsers[UserSeperated];
            SPFieldUserValue UserName = new SPFieldUserValue(app, User.ID, User.LoginName);
        ListItem["Contact Person"] = UserCollection;
share|improve this question
up vote 1 down vote accepted

You can directly assign it as,

SPUser User = app.EnsureUser(UserSeperated);

In you above code, you are not using the value returned by the 'EnsureUser' method

share|improve this answer
Thanks Paddy..That's a really silly mistake from my side..Thanks for the help.. – Anil Oct 26 '12 at 13:42

Could you get the collection of the web using code below

  SPUser User = app.Site.RootWeb.SiteUsers[UserSeperated];

And then get specified user from this collection?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.