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 would like to add users from a people picker as separate list items to a custom list. Following code only saves the last person in my peoplepickerlist

string users = ppUsers.CommaSeparatedAccounts;
char[] splitter = { ',' };
string[] splitPPData = users.Split(splitter);

 SPList SiteAccessList = newSite.RootWeb.Lists["Site Access Rights"];
      newSite.RootWeb.AllowUnsafeUpdates = true;

 for (int i = 0; i < splitPPData.Length; i++)

                            if (!string.IsNullOrEmpty(loginName))
                                string LoginName=loginName;
                                SPUser user = newSite.RootWeb.EnsureUser("SPTEST\\"+ LoginName);
                             SPItem newEntry = SiteAccessList.Items.Add();
                            newEntry["Title"] = "New User";
                            newEntry["Permissions"] = "Contributor";
                            newEntry["UserName"] = user.Name.ToString();
                            newEntry["UserEmail"] = user.Email.ToString();
                        newSite.RootWeb.AllowUnsafeUpdates = false;
share|improve this question
up vote 1 down vote accepted

Are you missing some code? How does PPeople get created? You only create one newEntry object here, too, outside the loop. You might want to move that line inside the loop, just after the EnsureUser call.

share|improve this answer
Thanks James, that was the problem: SPItem newEntry = SiteAccessList.Items.Add(); Must be in my loop... – Wim Hill Oct 10 '11 at 14:16

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.