var peoplePicker = this."WhereYourControlAdded_Id".FindControl("PeoplePickerControlID") as PeopleEditor;
//here you should find your people picker control
PeopleEditor peoplePicker = value as PeopleEditor;
if (peoplePicker != null && peoplePicker.CommaSeparatedAccounts.ToString() != "")
{
string[] userarray = peoplePicker.CommaSeparatedAccounts.ToString().Split(',');
SPFieldUserValueCollection usercollection = new SPFieldUserValueCollection();
for (int i = 0; i < userarray.Length; i++)
{
SPFieldUserValue usertoadd = ConvertLoginAccount(userarray[i]);
usercollection.Add(usertoadd);
}
item[item.Fields[columnName].InternalName] = usercollection;
}
else
{
item[item.Fields[columnName].InternalName] = null;
}
public static SPFieldUserValue ConvertLoginAccount(string userid)
{
SPFieldUserValue uservalue = null;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb web = site.OpenWeb())
{
SPUser requireduser = web.EnsureUser(userid);
uservalue = new SPFieldUserValue(web, requireduser.ID, requireduser.LoginName);
}
}
});
return uservalue;
}
ConvertLoginAccount函數將解決您的問題。我分享了爲我工作的所有代碼。 –
謝謝CIAODO –
它解決了你的問題嗎? –