Get the Sharepoint user's additional information from Active Directory

 Get the Sharepoint user's additional information from Active Directory
Note: To add or read properties from an Active Directory group you need to have special username and password like an Active Directory admin.

 SPUser currentUser = web.CurrentUser;
string userID = currentUser.LoginName;
string newUserID = userID.Remove(0, 6).ToUpper();
// GET THE USER'S info FROM THE ACTIVE DIRECTORY
string usrPath = "LDAP://CN=" + userID.Remove(0, 6).ToUpper();
UsrPath += ",OU=UserAccounts,DC=aaaaa,DC=com";

DirectoryEntry UserInAD;
UserInAD = new DirectoryEntry(usrPath);
string UsrPhone = UserInAD.Properties["telephoneNumber"].Value.ToString();
string UserEmail = UserInAD.Properties["mail"].Value.ToString();
string MgrFromAD = UserInAD.Properties["Manager"].Value.ToString();
string managerLogin = "Company\\" + MgrFromAD.Substring(3, 7).ToLower();

Here we get Manager information from Active Directory of the currently logged in user in sharepoint.

Leave your comments below.


No comments: