please help I Cannot Add Multiple users to a SPFieldUserValueCollection without removing the previous one. evertime I add to my collection the previous user gets removed. here is my code below.

spWeb.AllowUnsafeUpdates = true;

SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection(spWeb, LearningCalendar_Item["Course Attendies"].ToString());
usercollection.Add(new SPFieldUserValue(spWeb, SPContext.Current.Web.CurrentUser.ID, SPContext.Current.Web.CurrentUser.Name.ToString()));
LearningCalendar_Item["Course Attendies"] = usercollection;

spWeb.AllowUnsafeUpdates = false;

Try the below code:

spWeb.AllowUnsafeUpdates = true;

SPUser user = spWeb.EnsureUser(SPContext.Current.Web.CurrentUser.LoginName);   

SPFieldUserValueCollection values = (SPFieldUserValueCollection)LearningCalendar_Item["Course Attendies"];

values.Add(new SPFieldUserValue(web, user.ID, user.Name));

LearningCalendar_Item["Course Attendies"] = values;


spWeb.AllowUnsafeUpdates = false;
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.