citizenzen
Programmer
I have a simple web service which enables me to search for user information in active directory. Initially, I was only showing 'displayName', but now I need to show at least 4 more properties. I would like to load the properties in an array, but this does not seem to work as I want to return a the array value. Is it possible to return an array for the properties? Or should I create separate functions within the webservice for these properties? Thanks in advance.
This is what I have:
This is what I have:
Code:
public string getUserInfo(string user)
{
string adpath = "LDAP://path information here";
try
{
DirectoryEntry entry = new DirectoryEntry(adpath);
DirectorySearcher dsearch = new DirectorySearcher(entry);
String account = user.ToString();
user = this.User.Identity.Name.ToString();
dsearch.Filter="(&(objectClass=User)(sAMAccountName="+ account +"))";
dsearch.PropertiesToLoad.Add("displayName");
dsearch.PropertiesToLoad.Add("l");
dsearch.PropertiesToLoad.Add("departmentName");
SearchResult myresult = dsearch.FindOne();
if (myresult != null)
{
return myresult.Properties["displayName"][0].ToString() + myresult.Properties["l"][1].ToString();
}
else
{
return "Unknown User";
}
}
catch (Exception ex)
{
string debug = ex.Message;
return "ERROR LOADING THE DATA: " + debug;
}
}