Hi Guys, Thanks for visiting our blog . In this Post , We are going to get User data from Active Directory in C# . We can also use the code in SharePoint also as per the requirement. Please find the code for getting user details from AD (Active directory ). Before writing the code We need to get System.DirectoryServices dll from assembiles. into the page.
protected void btnSubmit_Click(object sender, EventArgs e) { try { string connection = "LDAP:// server name"; // LDAP Server Name DirectorySearcher dssearch = new DirectorySearcher(connection); dssearch.Filter = "(sAMAccountName=" + txtusername.Text + ")"; // Passing UserName SearchResult sresult = dssearch.FindOne(); DirectoryEntry dsresult = sresult.GetDirectoryEntry(); // retrieving data string FirstName = dsresult.Properties["givenName"][0].ToString(); string LastName = dsresult.Properties["sn"][0].ToString(); string EmailID = dsresult.Properties["mail"][0].ToString(); } catch (Exception ex) { //Exception Handling } }
0 comments:
Post a Comment