Objective In this article, I am going to explain, how to insert multi user or more than one user in Share point list. About SharePoint list where value would be inserted
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using Microsoft.SharePoint;
namespace TestingMultipleUsre{ public partial class _Default : System.Web.UI.Page { SPWeb _web; SPSite _site; SPList myList protected void Page_Load(object sender, EventArgs e) { string usercontrolvalue = "dhananjay,arun,anoj,patra,mub"; _site = new SPSite("http://adfsaccount:2222/"); _web = _site.OpenWeb(); myList = _web.Lists["TestingUser"]; _web.AllowUnsafeUpdates = true ; myList = _web.Lists["TestingUser"]; SPListItem item = myList.Items.Add(); SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection(); string[] userarray = usercontrolvalue.Split(','); for (int i = 0; i < userarray.Length; i++) { SPFieldUserValue usertoadd = ConvertLoginName(userarray[i]); usercollection.Add(usertoadd); } item["UserTest"] = usercollection; item.Update(); } public SPFieldUserValue ConvertLoginName(string userid) { SPUser requireduser = _web.EnsureUser(userid); SPFieldUserValue uservalue = new SPFieldUserValue(_web, requireduser.ID, requireduser.LoginName); return uservalue; } }}Note: Make sure all the users; you are adding are user of the Sharepoint. OutputWhile running output would be as below Conclusion In this article, I have explained how to insert more than one user in SharePoint list. Thanks for reading.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: