Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)
        {

            app.EnsureUser(UserSeperated);
            SPUser User = app.SiteUsers[UserSeperated];
            SPFieldUserValue UserName = new SPFieldUserValue(app, User.ID, User.LoginName);
            UserCollection.Add(UserName);
        }
        ListItem["Contact Person"] = UserCollection;
share|improve this question

2 Answers 2

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

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

And then get specified user from this collection?

share|improve this answer

Your Answer

 
discard

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.