Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get user email with loginname programmatically in sharepoint?

Tags:

sharepoint

I have a search function that returns the email for a user when I have the user's ID

private string getUserEmail(string userID)
{
    string userEmail = null;
    SPGroupCollection collGroups = SPContext.Current.Web.Groups;
    int userIDint = Convert.ToInt32(userID);
    foreach (SPGroup oGroup in collGroups)
    {
        userEmail = oGroup.Users.GetByID(userIDint).Email.ToString();
    }
    return userEmail;
}

with Users I can do either GetByID or GetByEmail but what should I do if I have the domain name such as MyDomain\myUsername and want the email for that user?

Any help or links would be appreciated.

Thanks in advance.

like image 806
peter Avatar asked Jan 18 '11 06:01

peter


1 Answers

http://msdn.microsoft.com/en-us/library/ms414398.aspx

SPContext.Current.Web.AllUsers["loginname"].Email

http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.ensureuser.aspx

SPContext.Current.Web.EnsureUser("loginname").Email
like image 85
djeeg Avatar answered Oct 29 '22 18:10

djeeg