gpt4 book ai didi

c# - SharePoint 人物编辑器不显示用户

转载 作者:太空宇宙 更新时间:2023-11-03 13:26:46 27 4
gpt4 key购买 nike

我有一个要求,我必须将保存的用户显示到 SharePoint 人员编辑器控件。为此,我将用户名保存到 People/Group 列。我正在使用以下代码将这些用户带到人物编辑器控件中:

SetPeopleEditor(item, Constants.FieldNames.IT_DIRECTOR, pe_ITDirector, oWeb);

上述方法的定义如下所示:

        private PickerEntity SetPeopleEditor(SPListItem item, string columnName, PeopleEditor peopleEditor, SPWeb web)
{
ArrayList entityArrayList = new ArrayList();
PickerEntity entity = null;
if (item[columnName] != null)
{
char[] to_splitter = { ';' };
string to_list = item[columnName].ToString(); // Reads value stored in SPList. (i.e., "Domain\User1; Domain\User2")
string[] arr = to_list.Split(to_splitter);
string user = string.Empty;
for (int i = 1; i < arr.Length; i++)
{
if ((i % 2) != 0)
{
user = arr[i].Substring(arr[i].IndexOf("#") + 1);
entity = new PickerEntity();
entity.Key = user;
entity.IsResolved = true;
entity = peopleEditor.ValidateEntity(entity);
entityArrayList.Add(entity);
}
}


}
return entity;
}

但不幸的是,控件总是显示空值。如何通过将数据填充到人员编辑器控件来实现此目的?

最佳答案

您可以按如下方式进行,

SPFieldUserValueCollection userValueCollection =
new SPFieldUserValueCollection(SPContext.Current.Web, SPContext.Current.Item["ColumnName"] as string);
if (userValueCollection .Count > 0)
{
spPeoplePickerContol.CommaSeparatedAccounts = userValueCollection[0].User.LoginName;
}

关于c# - SharePoint 人物编辑器不显示用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22142100/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com