Hi,
I have a problem when adding user to SharePoint group programmatically using SharePoint people picker control. If I try to add the user manually inside the group, the user will be accepted and if I add the user to the website first, then I can add the user programmatically. The problem exists when the user is not exist in the website. Below is my code for further reference.
PickerEntity pe = (PickerEntity)upTenderOwner.ResolvedEntities[i]; userCollTO.Add(new SPFieldUserValue(SPContext.Current.Web, Convert.ToInt32(pe.EntityData["SPUserID"]), pe.Key)); foreach (SPFieldUserValue spfuv in userCollTO) { SPUser user = spfuv.User; web.AllowUnsafeUpdates = true; SPUser spUsr = web.EnsureUser(user.LoginName); if (spUsr != null) { SPGroup spGrp = web.Groups[grpTO.Name]; if (spGrp != null) { spGrp.AddUser(spUsr); } } web.AllowUnsafeUpdates = false;Any help is much appreciated. Thank you.
wawa87