public SPFieldUserValue ConvertLoginAccount(string userid)
{
SPFieldUserValue uservalue;
using (SPSite site = new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb web = site.OpenWeb())
{
SPUser requireduser = web.EnsureUser(userid);
uservalue = new SPFieldUserValue(web, requireduser.ID, requireduser.LoginName);
}
}
return uservalue;
}
//user collection in array
string[] userarray = lblFunctionTeam.Text.ToString().Split(';');
SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection();
for (int i = 0; i < userarray.Length - 1; i++)
{
SPFieldUserValue usertoadd = ConvertLoginAccount(userarray[i]);
usercollection.Add(usertoadd);
}
//set multiuserCollection
item["UserCollectionField"] = usercollection;
//single user Value
SPFieldUserValue usertoadd1= ConvertLoginAccount("userIdentityEmailOrLoginName");
item["UserField"] =usertoadd1;
No comments:
Post a Comment