Active Directory Search

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • radcaesar
    Recognized Expert Contributor
    • Sep 2006
    • 759

    Active Directory Search

    Hi All,
    I had wrote a method to compare the users of AD and a oracle user table. Here using datarow, i search each users in AD.

    My code workin fine for first record, but it fails ffom serching the second record onwards.

    I was confused why this Findone() mthod returns null from the second record.

    Code:
    private void GetFDSUsers()
        {
            DirectoryEntry FDSDE = GetFDSObject();
            DirectorySearcher FDSSearcher = new DirectorySearcher();
            DataView dv = (DataView)  CSIDataSource.Select(DataSourceSelectArguments.Empty);
    
            foreach (DataRow dr in dv.Table.Rows)
            {
                string SearchName = dr[0].ToString().ToUpper();
                //string SearchName = "SMANIKA5";
                FDSSearcher.SearchRoot = FDSDE;
                FDSSearcher.Filter = "(&(objectClass=user)(SAMAccountName=" + SearchName + "))";
             
                // FDSSearcher.Filter = "(&(objectClass=user)(SAMAccountName=SMANIKA5))";
                
                FDSSearcher.SearchScope = SearchScope.Subtree;
                SearchResult FDSSearchResult = FDSSearcher.FindOne();
                
    
                if (!(null == FDSSearchResult))
                {
                    FDSDE = new DirectoryEntry(FDSSearchResult.Path, "username", "password", AuthenticationTypes.Secure);
    
                    Response.Write(FDSDE.Name.ToString()+"\r");
                    //Response.Write(FDSDE.Username);
                    Response.Write(FDSDE.Properties["DisplayName"].Value.ToString());
                    //return FDSDE;
                }
                else
                {
                    //Response.Write("Else Part, Record not found");
                    //return null;
                }            
           }
    Last edited by kenobewan; Mar 27 '07, 02:40 AM. Reason: Add code tags
  • radcaesar
    Recognized Expert Contributor
    • Sep 2006
    • 759

    #2
    No Replies Yet ? Its Bad buddies.

    I Had solved that and its fine now.

    :)

    Comment

    • kenobewan
      Recognized Expert Specialist
      • Dec 2006
      • 4871

      #3
      So you used findall() instead?

      Comment

      Working...