User283571144 posted
Hi asif62000,
According to your codes, I found your Get method return value's type is IEnumerable<string>
, but the lstADUsers's type is List<Users>
. We couldn't directly convert the List<Users> to IEnumerable<string>.
If you want to return a list of the Users, I suggest you could try to use List<Users> or IEnumerable<Users> as the result type.
More details, you could refer to below codes:
public List<Users> Get()
{
List<Users> lstADUsers = new List<Users>();
string DomainPath = "LDAP://DC=teksite,DC=local";
DirectoryEntry searchRoot = new DirectoryEntry(DomainPath);
DirectorySearcher search = new DirectorySearcher(searchRoot);
search.Filter = "(&(objectClass=user)(objectCategory=person))";
search.PropertiesToLoad.Add("samaccountname");
search.PropertiesToLoad.Add("mail");
search.PropertiesToLoad.Add("usergroup");
search.PropertiesToLoad.Add("displayname");//first name
SearchResult result;
SearchResultCollection resultCol = search.FindAll();
if (resultCol != null)
{
for (int counter = 0; counter < resultCol.Count; counter++)
{
string UserNameEmailString = string.Empty;
result = resultCol[counter];
if (result.Properties.Contains("samaccountname") &&
result.Properties.Contains("mail") &&
result.Properties.Contains("displayname"))
{
Users objSurveyUsers = new Users();
objSurveyUsers.Email = (String)result.Properties["mail"][0] +
"^" + (String)result.Properties["displayname"][0];
objSurveyUsers.UserName = (String)result.Properties["samaccountname"][0];
objSurveyUsers.DisplayName = (String)result.Properties["displayname"][0];
lstADUsers.Add(objSurveyUsers);
}
}
string lines = string.Join(Environment.NewLine, lstADUsers);
return lstADUsers; // here I get error
}
return lstADUsers; // here I get error
}
Best Regards,
Brando