c# get sharepoint user name or email address
-------
static public string GetUserEMail(object user, ClientContext context)
{
Dictionary
if (user == null)
{
return string.Empty;
}
var username = string.Empty;
var useremail = string.Empty;
var spUser = user as FieldUserValue;
if (spUser != null)
{
if (!userNameCache.TryGetValue(spUser.LookupId, out useremail))
{
var userInfoList = context.Web.SiteUserInfoList;
context.Load(userInfoList);
var query = new CamlQuery { ViewXml = "
var users = userInfoList.GetItems(query);
context.Load(users, items => items.Include(
item => item.Id,
item => item["Name"]));
var principal = users.GetById(spUser.LookupId);
context.Load(principal);
context.ExecuteQuery();
username = principal["Name"] as string;
useremail = username.Substring(username.IndexOf("\\") + 1) + "@test.com";
userNameCache.Add(spUser.LookupId, useremail);
}
}
return useremail;
}
Apr 29, 2011
Get sharepoint user name or email address
張貼者: Brian 於 09:00
標籤: Sharepoint 2010
Subscribe to:
Post Comments (Atom)
0 意見:
Post a Comment