[英]Sharepoint 2013, get data from list to ClientPeoplePicker
在Sharepoint 2013中,我嘗試從自定義列表中獲取用戶信息以在“編輯”表單中顯示,該表單將顯示在控件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形式覆蓋它們:受保護的覆蓋void OnFormControlDataBinding(object sender,EventArgs e)
這是我得到的錯誤:
在程序集“ Microsoft.SharePoint,版本= 15.0.0.0,區域性=中性,PublicKeyToken = 71e9bce111e9429c”中,鍵入“ Microsoft.SharePoint.SPUser”未標記為可序列化。
說明:執行當前Web請求期間發生未處理的異常。 請查看堆棧跟蹤,以獲取有關錯誤及其在代碼中起源的更多信息。
異常詳細信息:System.Runtime.Serialization.SerializationException:程序集“ Microsoft.SharePoint,版本= 15.0.0.0,區域性=中性,PublicKeyToken = 71e9bce111e9429c”中的類型“ Microsoft.SharePoint.SPUser”未標記為可序列化。
源錯誤:
當前Web請求的執行期間生成了未處理的異常。 可以使用下面的異常堆棧跟蹤來標識有關異常的來源和位置的信息。
堆棧跟蹤:
[SerializationException:程序集'Microsoft.SharePoint,版本= 15.0.0.0,文化=中性,PublicKeyToken = 71e9bce111e9429c'中的類型'Microsoft.SharePoint.SPUser'未標記為可序列化。] System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType類型)+14210117 System.Runtime.Serialization.FormatterServices.GetSerializableMembers(類型,StreamingContext上下文)+408 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()+420 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo .InitSerialize(對象obj,ISurrogateSelector surrogateSelector,StreamingContext上下文,SerObjectInfoInit serObjectInfoInit,IFormatterConverter轉換器,ObjectWriter objectWriter,SerializationBinder綁定器)+532 System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialroro(Object Selector,IS serObjectInfoInit,IFormatterConverter轉換器,對象 ctWriter objectWriter,SerializationBinder活頁夾)+270 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(對象圖,Header [] inHeaders,__BinaryWriter serWriter,布爾fCheck)+814 System.Runtime.Serialization.Formatters.Binary.BinaryFormat 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,對象值)+3526
[ArgumentException:序列化類型為'Microsoft.SharePoint.SPUser。'的值'i:0#.w | fsoft.fpt.vn \\ hoavt2'的錯誤] System.Web.UI.ObjectStateFormatter.SerializeValue(SerializerBinaryWriter編寫器,對象值)+ 4068 System.Web.UI.ObjectStateFormatter.Serialize(對象狀態圖,目的)+103 System.Web.UI.Util.SerializeWithAssert(IStateFormatter2格式化程序,對象stateGraph,目的)+67 System.Web.UI.HiddenFieldPageStatePersister.Save( )+173 System.Web.UI.Page.SaveAllState()+1161 System.Web.UI.Page.ProcessRequestMain(布爾值includeStagesBeforeAsyncPoint,布爾值includeStagesAfterAsyncPoint)+4660
任何人都面臨該問題,請提供幫助。
我發現我錯了:)它不在那個函數中,在另一個函數中
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)到擴展方法,然后發生上述錯誤。
這可能對你們有幫助。
謝謝!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.