Active Directory searches

  • Thread starter Thread starter Stephan Bour
  • Start date Start date
S

Stephan Bour

Hi,
I am trying to authenticate form users using a local Active Directory server
and I get the following error message at compile:

Compiler Error Message: CS0029: Cannot implicitly convert type 'object' to
'string'
Source Error:

mName = res.Properties["Name"][0];
mLocation = res.Properties["streetaddress"][0];
mUserID = res.Properties["samaccountname"][0];
mTelephone = res.Properties["telephonenumber"][0];
mEmail = res.Properties["mail"][0];

Any idea what I'm doing wrong?

Thanks for your help,
Stephan.

Here is the whole code block:

public class ADCredentials {
private String mName;
private String mEmail;
private String mLocation;
private String mUserID;
private String mTelephone;

public ADCredentials (String UserID) {
DirectoryEntry de = new
DirectoryEntry("LDAP://NIAID-DC14/CN=Users,DC=NIAID,DC=NIH,DC=GOV","name",
"pass");
DirectorySearcher ds = new
DirectorySearcher("(&(objectCategory=Person)(objectClass=user)(samaccountnam
e=" + UserID + "))");
//Point the Root search to the previous directory entry.
ds.SearchRoot = de;
//Narrow the search scope to current subtree.
ds.SearchScope = SearchScope.Subtree;
SearchResult res = ds.FindOne();
mName = res.Properties["Name"][0];
mLocation = res.Properties["streetaddress"][0];
mUserID = res.Properties["samaccountname"][0];
mTelephone = res.Properties["telephonenumber"][0];
mEmail = res.Properties["mail"][0];
}

public String Name {
get {
return mName;
}
}

public String Email {
get {
return mEmail;
}
}

public String Location {
get {
return mLocation;
}
}

public String UserID {
get {
return mUserID;
}
}

public String Telephone {
get {
return mTelephone;
}
}
}
 
The following loop should help you get what you need.

foreach (string sPropName in srResults.Properties.PropertyNames)
{
if (sNameValue == sPropName)
{
foreach (string sValue in srResults.Properties[sPropName])
{
sRetValue = sValue;
}
}
 
Back
Top