Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从人员编辑器控件获取值?_C#_Sharepoint_Peoplepicker - Fatal编程技术网

C# 从人员编辑器控件获取值?

C# 从人员编辑器控件获取值?,c#,sharepoint,peoplepicker,C#,Sharepoint,Peoplepicker,我创建了一个可视化Web部件,其中包含一个people Editor控件,用于选择管理者名称(实际上只有一个名称)。 控件工作正常,但我希望在单击按钮期间使用代码将特定值存储到变量。我怎样才能做到这一点?有什么帮助吗?我得到了答案。谢谢你的建议。 下面是对我来说很好用的代码 SPWeb mySite = SPContext.Current.Web; SPListItemCollection listItems = mySite.Lists["myList"].Items;

我创建了一个可视化Web部件,其中包含一个people Editor控件,用于选择管理者名称(实际上只有一个名称)。
控件工作正常,但我希望在单击按钮期间使用代码将特定值存储到变量。我怎样才能做到这一点?有什么帮助吗?

我得到了答案。谢谢你的建议。 下面是对我来说很好用的代码

    SPWeb mySite = SPContext.Current.Web;

    SPListItemCollection listItems = mySite.Lists["myList"].Items;

    SPListItem item = listItems.Add();

    string[] UsersSeperated = pplEditor.CommaSeparatedAccounts.Split(',');

    SPFieldUserValueCollection UserCollection = new SPFieldUserValueCollection();

    foreach (string UserSeperated in UsersSeperated)

       {

    mySite.EnsureUser(UserSeperated);

    SPUser User = mySite.SiteUsers[UserSeperated];

    SPFieldUserValue UserName = new SPFieldUserValue(mySite, User.ID, User.LoginName);

    UserCollection.Add(UserName);

   }

item["people"] = UserCollection;

item.Update();

希望这段代码对你有帮助

public void btnSave_Click(object sender, System.EventArgs e)
{
   ….
   //where userPicker is Id of People picker control
   PickerEntity pe = (PickerEntity)userPicker.Entities[0];  
   string username = pe.Description;
   …
}