Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.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# SharePoint人员编辑器不显示用户_C#_Asp.net_Sharepoint_Peoplepicker - Fatal编程技术网

C# SharePoint人员编辑器不显示用户

C# SharePoint人员编辑器不显示用户,c#,asp.net,sharepoint,peoplepicker,C#,Asp.net,Sharepoint,Peoplepicker,我需要将保存的用户显示到SharePoint人员编辑器控件。为此,我将用户名保存到“人员/组”列。我使用以下代码将这些用户带到people editor控件: SetPeopleEditor(item, Constants.FieldNames.IT_DIRECTOR, pe_ITDirector, oWeb); 上述方法的定义如下所示: private PickerEntity SetPeopleEditor(SPListItem item, string columnNam

我需要将保存的用户显示到SharePoint人员编辑器控件。为此,我将用户名保存到“人员/组”列。我使用以下代码将这些用户带到people editor控件:

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;
    }
private PickerEntity SetPeopleEditor(SPListItem、string columnName、PeopleEditor、SPWeb web)
{
ArrayList entityArrayList=新的ArrayList();
PickerEntity实体=null;
如果(项[columnName]!=null)
{
char[]to_splitter={';'};
字符串to_list=item[columnName].ToString();//读取存储在SPList中的值。(即,“域\用户1;域\用户2”)
字符串[]arr=to_list.Split(to_splitter);
string user=string.Empty;
对于(int i=1;i
但不幸的是,控件总是显示空值。如何通过向people editor控件填充数据来实现这一点?

您可以执行以下操作:

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

您必须在验证实体后包含peopleEditor.Entities.Add(实体),才能将实体添加到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);
                    }
                }
            }
        }
private void SetPeopleEditor(SPListItem项、字符串列名、PeopleEditor、PeopleEditor、SPWeb)
{
如果(项[columnName]!=null)
{
char[]to_splitter={';'};
字符串to_list=item[columnName].ToString();//读取存储在SPList中的值。(即,“域\用户1;域\用户2”)
字符串[]arr=to_list.Split(to_splitter);
string user=string.Empty;
对于(int i=1;i
试试这个:




我认识一些我想编辑的人。您的解决方案也允许编辑行为吗?谢谢您的回答。但不幸的是,同样的情况。未显示用户名..您已调试并看到。您是否在userVauesCollection中获得了正确的值?
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();
                    }

                }