Sharepoint 2013,从列表中获取数据到ClientPeoplePicker

本文关键字:获取 数据 ClientPeoplePicker 列表 2013 Sharepoint | 更新日期: 2023-09-27 18:15:59

我试图从自定义列表中获取用户信息,以显示在编辑表单中,这将显示在控制ClientPeoplePicker。

我四处搜索并尝试了2个解决方案:

private void LoadUserToPeoplePicker(SPListItem item, string colName, ClientPeoplePicker peoplePicker)
    {
        //Get user information from list
        var user = item[colName] as string;
        if (!string.IsNullOrEmpty(user))
        {
            var spUser = new SPFieldUserValue(SPContext.Current.Web, user);
            //Solution 01
            var entity = new PickerEntity();
            entity.Key = spUser.LookupValue;
            PeopleEditor editor = new PeopleEditor();
            entity = editor.ValidateEntity(entity);
            peoplePicker.AddEntities(new List<PickerEntity> { entity });
            //Solution 02
            //if (!string.IsNullOrEmpty(spUser.User.Email))
            //{
            //    peoplePicker.InitialUserAccounts = spUser.User.Email;
            //}
        }
    }

我在Nintex形式的覆盖中调用它们:protected override void OnFormControlDataBinding(object sender, EventArgs e)

这里是错误我得到:

Microsoft.SharePoint类型"。SPUser' in Assembly 'Microsoft。SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'未标记为可序列化

描述:当前web请求执行过程中出现未处理的异常。请查看堆栈跟踪以获得有关错误及其在代码中的起源位置的更多信息。

异常详细信息:system . runtime . serialize . serializationexception: Type 'Microsoft.SharePoint. sharepoint . 'SPUser' in Assembly 'Microsoft。SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'未标记为可序列化

源错误:

在执行当前web请求期间生成了一个未处理的异常。有关异常的来源和位置的信息可以使用下面的异常堆栈跟踪来识别。

堆栈跟踪:

[SerializationException: Type 'Microsoft.SharePoint。SPUser' in Assembly 'Microsoft。SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'未标记为可序列化的。System.Runtime.Serialization.FormatterServices。InternalGetSerializableMembers(RuntimeType type) +14210117System.Runtime.Serialization.FormatterServices。GetSerializableMembers(Type Type, StreamingContext context) +408System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo () + 420System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo。InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit SerObjectInfoInit, IFormatterConverter转换器,ObjectWriter ObjectWriter, SerializationBinder绑定器)+532System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo。Serialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit SerObjectInfoInit, IFormatterConverter转换器,ObjectWriter ObjectWriter, SerializationBinder绑定器)+270System.Runtime.Serialization.Formatters.Binary.ObjectWriter。Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck) +814System.Runtime.Serialization.Formatters.Binary.BinaryFormatter。Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck) +322System.Runtime.Serialization.Formatters.Binary.BinaryFormatter。Serialize(流serializationStream,对象图)+17System.Web.UI.ObjectStateFormatter。SerializeValue(SerializerBinaryWriter writer,对象值)+3526

[ArgumentException: serializing value 'i:0#.w|fsoft.fpt.]vn'hoavt2'的类型'Microsoft.SharePoint.SPUser.']System.Web.UI.ObjectStateFormatter。SerializeValue(SerializerBinaryWriter写入器,对象值)+4068System.Web.UI.ObjectStateFormatter。Serialize(对象状态图,目的)+103System.Web.UI.Util。SerializeWithAssert(IStateFormatter2 formatter, Object statgraph, Purpose Purpose) +67System.Web.UI.HiddenFieldPageStatePersister.Save () + 173System.Web.UI.Page.SaveAllState () + 1161System.Web.UI.Page。ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4660

有谁正面临这个问题,请帮助。

Sharepoint 2013,从列表中获取数据到ClientPeoplePicker

我发现我错了。它不在那个函数中,它在另一个

private void ExtractValueForApprover(IOrderedDictionary dictionary, ClientPeoplePicker peoplePicker,
        string colName)
    {
        if (peoplePicker == null || string.IsNullOrEmpty(colName))
        {
            return;
        }
        if (peoplePicker.ResolvedEntities.Count > 0)
        {
            var user = SPContext.Current.Web.EnsureUser(peoplePicker.GetPickerEntity().Key);
            AddValueToDictionary(colName, user.LoginName, dictionary);
        }
    }

我提取了这一行:SPContext.Current.Web.EnsureUser(peoplePicker.GetPickerEntity(). key)扩展方法,然后上面的错误发生了

这可能对你们有帮助。

谢谢!