在Sharepoint 2013中, 我尝试从自定义列表中获取用户信息以在编辑表单中显示,该表单将显示在控件ClientPeoplePicker中。
我四处寻找并尝试了两种解决方案:
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)
这是我得到的错误:
键入&#39; Microsoft.SharePoint.SPUser&#39;在Assembly&#39; Microsoft.SharePoint,Version = 15.0.0.0,Culture = neutral,PublicKeyToken = 71e9bce111e9429c&#39;未标记为可序列化。
描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
异常详细信息:System.Runtime.Serialization.SerializationException:键入&#39; Microsoft.SharePoint.SPUser&#39;在Assembly&#39; Microsoft.SharePoint,Version = 15.0.0.0,Culture = neutral,PublicKeyToken = 71e9bce111e9429c&#39;未标记为可序列化。
来源错误:
在执行当前Web请求期间生成了未处理的异常。可以使用下面的异常堆栈跟踪来识别有关异常的起源和位置的信息。
堆栈追踪:
[SerializationException:Type&#39; Microsoft.SharePoint.SPUser&#39;在Assembly&#39; Microsoft.SharePoint,Version = 15.0.0.0,Culture = neutral,PublicKeyToken = 71e9bce111e9429c&#39;未标记为可序列化。] System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)+14210117 System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type,StreamingContext context)+408 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()+ 420 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj,ISurrogateSelector surrogateSelector,StreamingContext context,SerObjectInfoInit serObjectInfoInit,IFormatterConverter converter,ObjectWriter objectWriter,SerializationBinder binder)+532 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize(Object obj,ISurrogateSelector surrogateSelector,StreamingContext context,SerObjectInfoInit serObjectInfoInit,IFormatterConverter converter,ObjectWriter objectWriter,SerializationBinder binder)+270 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph,Header [] inHeaders,__BinaryWriter serWriter,Boolean fCheck)+814 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream,Object graph,Header [] headers,Boolean fCheck)+322 System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream,Object graph)+17 System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer,Object value)+3526
[ArgumentException:错误序列化值&#39; i:0#.w | fsoft.fpt.vn \ hoavt2&#39;类型&#39; Microsoft.SharePoint.SPUser。&#39;] System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter writer,Object value)+4068 System.Web.UI.ObjectStateFormatter.Serialize(Object stateGraph,Purpose purpose)+103 System.Web.UI.Util.SerializeWithAssert(IStateFormatter2 formatter,Object stateGraph,Purpose purpose)+67 System.Web.UI.HiddenFieldPageStatePersister.Save()+173 System.Web.UI.Page.SaveAllState()+ 1161 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+4660
任何人都面临着这个问题,请帮助。
答案 0 :(得分:0)
我发现我错了:) 它不在那个功能中,它在另一个
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)到扩展方法,然后发生上面的错误。
这对你们有帮助。
谢谢!