Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- active directory findone() method
- DirectoryEntry de = null;
- SearchResult results = null;
- de = new DirectoryEntry();
- //geting the result FROM ad
- de.Path = dr.manager;
- de.AuthenticationType = AuthenticationTypes.Secure;
- DirectorySearcher search = new DirectorySearcher(de);
- search.Filter = string.Format("(objectClass={0})",'*');
- search.PropertiesToLoad.Add("IsraelID");
- results = search.FindOne();
- de = results.GetDirectoryEntry();
- System.Runtime.InteropServices.COMException (0x80004005): Unspecified error
- at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
- at System.DirectoryServices.DirectoryEntry.Bind()
- at System.DirectoryServices.DirectoryEntry.get_AdsObject()
- at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
- at System.DirectoryServices.DirectorySearcher.FindOne()
- string LDAP = "LDAP://DC=MYDOMAIN,DC=COM";
- using (DirectoryEntry dirEntry = new DirectoryEntry(LDAP, null, null, AuthenticationTypes.Secure))
- using (DirectorySearcher dirSearch = new DirectorySearcher(
- dirEntry,
- string.Concat("(objectClass=*)"),
- new string[] { "IsraelID" }))
- {
- SearchResult result = dirSearch.FindOne();
- if (result != null)
- return result.Properties["IsraelID"][0].ToString();
- else
- return null;
- }
- DirectoryEntry de = null;
- SearchResult results = null;
- de = new DirectoryEntry();
- // Assuming your domain dns name is treyresearch.net
- de.Path = "LDAP://servername/CN=users,DC=treyresearch,DC=net";
- de.AuthenticationType = AuthenticationTypes.Secure;
- de.Username = "treyresearch\Administrator";
- de.Password = "P@$$W0rd";
- DirectorySearcher search = new DirectorySearcher(de);
- search.Filter = string.Format("(objectClass={0})",'*');
- search.PropertiesToLoad.Add("IsraelID");
- results = search.FindOne();
- de = results.GetDirectoryEntry();
- /* Connection to Active Directory
- */
- DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/dc=dom,dc=fr", "jpb", "Pwd");
- //DirectoryEntry deBase = new DirectoryEntry("LDAP://WM2008R2ENT:389/dc=dom,dc=fr");
- /* Directory Search
- */
- DirectorySearcher dsLookForOUs = new DirectorySearcher(deBase);
- dsLookForOUs.Filter = "(objectCategory=organizationalUnit)";
- dsLookForOUs.SearchScope = SearchScope.Subtree;
- dsLookForOUs.PropertiesToLoad.Add("cn");
- dsLookForOUs.PropertiesToLoad.Add("ou");
- SearchResultCollection srcOUs = dsLookForOUs.FindAll();
- foreach (SearchResult srOU in srcOUs)
- {
- Console.WriteLine("{0}", srOU.Path);
- }
- de.path=dr.dr.manager
- de.Path = "LDAP://"+dr.manager;
Add Comment
Please, Sign In to add comment