//public method return a list of staff users detail i.e List<UserObject> public List <UserObject> GetStaffUser(int value) { List <UserObject> UserList = new List <UserObject>(); char[] delimiter = new char[] { ',' }; if (value == 1) { DirectoryEntry deGroup = new DirectoryEntry(this.GetDirEntryPath(), this.GetDirUN(), this.GetDirPW()); deGroup.Path = this.GetStaffDirPath(); foreach (object oMember in deGroup.Properties["Member"]) { int iLocation = (oMember.ToString()).IndexOf("OU="); if (iLocation > 0) //if location greater than zero, futher drill to get users { DirectoryEntry de = new DirectoryEntry(this.GetDirEntryPath(), this.GetDirUN(), this.GetDirPW());; de.Path = "LDAP://" + oMember.ToString(); foreach (object w in de.Properties["Member"]) { //List<String> lst_userInoformation = new List<String>(); UserObject userObject = new UserObject(); DirectoryEntry de_user = new DirectoryEntry(this.GetDirEntryPath(), this.GetDirUN(), this.GetDirPW()); de_user.Path = "LDAP://" + w.ToString(); foreach (object fullName in de_user.Properties["displayName"]) { //lst_userInoformation.Add(s1.ToString()); userObject.FullName = fullName.ToString(); } foreach (object userName in de_user.Properties["title"]) { //lst_userInoformation.Add(s2.ToString()); userObject.UserName = userName.ToString().ToUpper(); } foreach (object email in de_user.Properties["mail"]) { //lst_userInoformation.Add(email.ToString()); userObject.Email = email.ToString(); int index = email.ToString().IndexOf("@"); userObject.UserName = email.ToString().Substring(0, index).ToUpper(); } UserList.Add(userObject); } } else { //List<String> lst_userInoformation = new List<String>(); UserObject userObject = new UserObject(); DirectoryEntry de_user = new DirectoryEntry(this.GetDirEntryPath(), this.GetDirUN(), this.GetDirPW()); de_user.Path = "LDAP://" + oMember.ToString(); foreach (object commonName in de_user.Properties["cn"]) {//lst_userInoformation.Add(s1.ToString()); userObject.UserName = commonName.ToString().ToUpper(); } foreach (object displayName in de_user.Properties["displayName"]) { userObject.FullName = displayName.ToString(); //lst_userInoformation.Add(displayName.ToString()); } foreach (object email in de_user.Properties["mail"]) { userObject.Email = email.ToString(); //lst_userInoformation.Add(email.ToString()); } UserList.Add(userObject); } } } return(UserList); }