3

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;
LearningCalendar_Item.Update();

spWeb.AllowUnsafeUpdates = false;
3

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;

LearningCalendar_Item.Update()

spWeb.AllowUnsafeUpdates = false;

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.