Skip to main content

Programmatically Adding Users and Groups to SharePoint List Item

SPSite WebApp = new SPSite(SitePath);
SPWeb Site = WebApp.OpenWeb();
Site.AllowUnsafeUpdates = true;
SPList TaskList = Site.Lists["PAQA Tasks"];

SPListItem NewTask = TaskList.Lists["PAQA Tasks"].Items.Add();

SPFieldUserValueCollection fv = new SPFieldUserValueCollection();
SPUserCollection usrColl = grpApprovers.Users;
foreach (SPUser grpUser in usrColl)
{
// add the new user into the collection
fv.Add(new SPFieldUserValue(Site, grpUser.ID, grpUser.Name));
}
NewTask["Assigned To"] = fv;


NewTask.Update();

Comments