Редактор людей SharePoint не отображает пользователей

У меня есть требование, согласно которому я должен отображать сохраненных пользователей в элементе управления редактором людей SharePoint. Для этого я сохраняю имена пользователей в столбце Люди/Группа. И я использую следующий код для передачи этих пользователей в управление редактором людей:

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;
    }

Но, к сожалению, элемент управления всегда показывает пустое значение. Как я могу добиться этого, заполнив данные в элементе управления редактором людей?


person Community    schedule 03.03.2014    source источник
comment
Я знаю нескольких человек, которых я хотел бы отредактировать. Ваше решение также позволяет редактировать поведение?   -  person uSeRnAmEhAhAhAhAhA    schedule 03.03.2014


Ответы (3)


Вы можете сделать следующее,

SPFieldUserValueCollection userValueCollection =
             new SPFieldUserValueCollection(SPContext.Current.Web, SPContext.Current.Item["ColumnName"] as string);
        if (userValueCollection .Count > 0)
        {
            spPeoplePickerContol.CommaSeparatedAccounts = userValueCollection[0].User.LoginName;
        }
person Jatin patil    schedule 03.03.2014
comment
Спасибо за Ваш ответ. Но, к сожалению, такая же ситуация. Не отображаются имена пользователей.. - person ; 03.03.2014
comment
вы отладили и видели. вы получаете правильные значения в userVauesCollection? - person Jatin patil; 03.03.2014

Вы должны включить peopleEditor.Entities.Add(entity) после проверки объекта, чтобы добавить объект в элемент управления peopleEditor.

 private void SetPeopleEditor(SPListItem item, string columnName, PeopleEditor peopleEditor, SPWeb web)
        {
            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);
                       PickerEntity entity  = new PickerEntity();
                        entity.Key = user;
                        entity.IsResolved = true;
                        entity = peopleEditor.ValidateEntity(entity);
                        peopleEditor.Entities.Add(entity);
                    }
                }
            }
        }
person Unnie    schedule 03.03.2014

Попробуй это:


string x = item["SP_Group"] == null ? "" : item["SP_Group"].ToString();

                if (x != "")
                {
                    SPFieldUserValue uv = new SPFieldUserValue(web, x);
                    SPGroup group = mySite.Groups.GetByID(uv.LookupId);

                    if (group.Users.Count > 0)
                    {
                        System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            foreach (SPUser sUser in group.Users)
                            {
                                PickerEntity entity = new PickerEntity();
                                entity.Key = sUser.LoginName;
                                entity = peopleEditor.ValidateEntity(entity);
                                entityArrayList.Add(entity);
                            }

                        });
                        peopleEditor.UpdateEntities(entityArrayList);
                        peopleEditor.Validate();
                    }
                    else
                    {
                        peopleEditor.Entities.Clear();
                    }

                }

string x = item["SP_Users"] == null ? "" : item["SP_Users"].ToString();

                if (x != "")
                {
                    SPFieldUserValueCollection uvcoll = new SPFieldUserValueCollection(mySite, x);                       

                    if (uvcoll.Count > 0)
                    {
                        System.Collections.ArrayList entityArrayList = new System.Collections.ArrayList();
                        SPSecurity.RunWithElevatedPrivileges(delegate()
                        {
                            foreach (SPFieldUserValue uv in uvcoll)
                            {
                                SPUser sUser = uv.User;
                                PickerEntity entity = new PickerEntity();
                                entity.Key = sUser.LoginName;
                                entity = peopleEditor.ValidateEntity(entity);
                                entityArrayList.Add(entity);
                            }

                        });
                        peopleEditor.UpdateEntities(entityArrayList);
                        peopleEditor.Validate();
                    }
                    else
                    {
                        peopleEditor.Entities.Clear();
                    }

                }
person Péter Kasó    schedule 20.10.2014