I have a list in SharePoint 2010 that has peoplepicker that I need to save from one to many groups to it. I've figured out how to save users, but stumped on saving many groups to a peoplepicker.
Example:
User selects one (or many) checkboxes. The value of each checkbox has a group name that is a group in my SharePoint site. I need to take these groups and save them to a people picker (inside one of my lists) that is configured to allow multiple entries.
Can someone provide and example or point me to a URL that will explain this?
Below is what I do for users. Is this close for groups? If so, can someone show me what to change to make this work for groups?
...
for (int i = 0; i < userarray.Length; i++)
{
assist = ConvertLoginName(web, userarray[i]);
if (assist != null)
parsedAssists += assist.User.ID.ToString(CultureInfo.InvariantCulture) + ";#" + assist.User.LoginName.ToString(CultureInfo.InvariantCulture) + ";#";
}
Hashtable ht = new Hashtable();
ht.Add("Assist", parsedAssists);
...
SPFile file = list.RootFolder.Files.Add(fileUpload.FileName, fileUpload.PostedFile.InputStream, ht, false);
private SPFieldUserValue ConvertLoginName(SPWeb web, string userId)
{
SPUser requireduser = web.EnsureUser(userId);
SPFieldUserValue uservalue = new SPFieldUserValue(web, requireduser.ID, requireduser.LoginName);
return uservalue;
}