I am using client object model to add items to splist. Here one field which is the email id I need to fill automatically after validation. If the user has a valid domain id. I want to extract the mail id
public static string checkUserEmail(string username, ClientContext clientContext)
{
string strEmail = string.Empty;
try
{
//ClientContext clientContext = new ClientContext(strSiteURL);
//clientContext.Load();
//List list = clientContext.Web.Lists.GetByTitle("TOM");
//ListItemCollection items = list.GetItems(CamlQuery.CreateAllItemsQuery());
//clientContext.Load(items);
clientContext.ExecuteQuery();
string strUserName = username.Trim();
User domainUser = clientContext.Web.EnsureUser(strUserName);
if (domainUser.ServerObjectIsNull == false)
{
strEmail = domainUser.Email;
}
else
{
strEmail = "";
}
}
catch (Exception ex)
{
Console.WriteLine("User check error {0}", ex.Message);
}
return strEmail;
}