0

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;
        }

1 Answer 1

0

Can you try like this:

string strUserName = username.Trim();
User domainUser = clientContext.Web.EnsureUser(strUserName);
clientContext.Load(domainUser);
clientContext.ExecuteQuery();

if (domainUser.ServerObjectIsNull == false)
{
   strEmail = domainUser.Email;
}
else
{
   strEmail = "";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.