È possibile ottenere la colonna che, come il FieldUserValue dalla lista, una volta che hai di utilizzare il valore di ricerca id e poi esegue una query contro il Siti User Informazioni List. Nell'esempio seguente memorizzo i risultati nella cache per evitare di cercare lo stesso id più di una volta poiché la query può essere costosa.
private readonly Dictionary<int, string> userNameCache = new Dictionary<int, string>();
public string GetUserName(object user)
{
if (user == null)
{
return string.Empty;
}
var username = string.Empty;
var spUser = user as FieldUserValue;
if (spUser != null)
{
if (!userNameCache.TryGetValue(spUser.LookupId, out username))
{
var userInfoList = context.Web.SiteUserInfoList;
context.Load(userInfoList);
var query = new CamlQuery { ViewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name='ID' /><Value Type='int'>" + spUser.LookupId + "</Value></Eq></Where></Query></View>" };
var users = userInfoList.GetItems(query);
context.Load(users, items => items.Include(
item => item.Id,
item => item["Name"]));
if (context.TryExecuteQuery())
{
var principal = users.GetById(spUser.LookupId);
context.Load(principal);
context.ExecuteQuery()
username = principal["Name"] as string;
userNameCache.Add(spUser.LookupId, username);
}
}
}
return username;
}
fonte
2010-12-15 01:57:34
utilizzando ctx.Web.EnsureUser lavorato come un fascino ... – onzur
LookupValue mi dà visualizzazione del nome e non il login nome. –