Directory Searcher Issues

I'm having trouble with some code. I'm trying to figure this out, but I keep hitting a road block…..

I keep getting stuck after everything is initialized. I'm not sure what is causing this.

Here is my code:

 Console.WriteLine("Please Enter the Address or Name of the DC or Domain you will be requesting information from."); String dc = Console.ReadLine(); String port = "389"; Console.WriteLine("Please Enter the DN path to the OU you wish to search."); String ou = Console.ReadLine(); Console.WriteLine("Enter your username:"); String authname = Console.ReadLine(); Console.WriteLine("Enter your password:"); String authpass = Console.ReadLine(); String ldaddress = "LDAP://" + dc + ":" + port + "/" + ou ; DirectoryEntry dir = new DirectoryEntry(ldaddress, authname, authpass); Console.WriteLine(dir.ToString()); Console.WriteLine(ldaddress); Console.ReadLine(); DirectorySearcher ds = new DirectorySearcher(dir); Console.WriteLine("Which User do you wish to pull information for?"); string un = Console.ReadLine(); ds.Filter = "(&(&(objectCategory=person)(ObjectClass=user))(samaccountname=" + un + "))"; ds.SearchScope = SearchScope.Subtree; SearchResult rs = ds.FindOne(); Console.Write(rs.GetDirectoryEntry().Properties["givenName"]); Console.Write(rs.GetDirectoryEntry().Properties["surName"].ToString()); 

Initially, I was getting an error at the line where I initialize "rs", and the error thrown was some sort of ComException stating the server returned a reference. Now when I compile and run, the error is that in the writeline calls, I get an error stating that "rs" isn't referencing an instance of the SearchResult class. The thing is there isn't a constructor for this class, and I can't exactly write one and have it be legit.

HELP!

by cjrutherford via /r/csharp

Leave a Reply