Hello,
I have the following code which queries all the users in an active directory. I need to get the group name and users full name for each user using c#.
Any help with code or a resource reference will of great help.
Thank you in advance.
private String adspath = "LDAP://dc=adserver,dc=netsweeper,dc=com";
private String username = "smanager";
private String password = "password";
private DBOperations dbdata ;
DirectoryEntry entry = new DirectoryEntry(this.adspath, this.username, this.password, AuthenticationTypes.Secure);
DirectorySearcher srch = new DirectorySearcher(entry);
//srch.SearchScope = SearchScope.Subtree;
srch.Filter = "(objectClass=User)";
foreach (SearchResult result in results)
{
if (result.Equals(null))
Console.WriteLine("Did not find any results");
else
Console.WriteLine("Initial find "+results.Count+" "+result.Path);
}
I have the following code which queries all the users in an active directory. I need to get the group name and users full name for each user using c#.
Any help with code or a resource reference will of great help.
Thank you in advance.
private String adspath = "LDAP://dc=adserver,dc=netsweeper,dc=com";
private String username = "smanager";
private String password = "password";
private DBOperations dbdata ;
DirectoryEntry entry = new DirectoryEntry(this.adspath, this.username, this.password, AuthenticationTypes.Secure);
DirectorySearcher srch = new DirectorySearcher(entry);
//srch.SearchScope = SearchScope.Subtree;
srch.Filter = "(objectClass=User)";
foreach (SearchResult result in results)
{
if (result.Equals(null))
Console.WriteLine("Did not find any results");
else
Console.WriteLine("Initial find "+results.Count+" "+result.Path);
}

Guest UserPosted Jan 19, 2008, 7:24 PM
http://www.c-sharpcorner.com/UploadFile/jodonnell/ListingADUsers07022005005138AM/ListingADUsers.aspx
kk mPosted Jan 17, 2008, 9:01 AM
Any soltion?>
Guest UserPosted Jan 16, 2008, 9:13 PM
Guest UserPosted Jan 16, 2008, 9:12 PM
string strFirstName, strUserName, strLastName, strEmailAddress;
srch.Filter = String.Format("(&(objectCategory=user)({0}={1}))", "SAMAccountName", strUserName); // strUserName is the domain username of the person you're looking for
.
.
.
if (result.Properties.Contains("givenname"))
strFirstName = (string)(result.Properties["givenname"][0]);
if (result.Properties.Contains("sn"))
strLastName = (string)(result.Properties["sn"][0]);
if (result.Properties.Contains("mail"))
strEmailAddress = (string)(result.Properties["mail"][0]);