The Active Directory datatype cannot be converted to/from a native DS datatype

  • Thread starter Thread starter Hechmi
  • Start date Start date
H

Hechmi

I am trying to retrieve the users of the company using active directory.

When i execute the code below , it gives the following error

"The Active Directory datatype cannot be converted to/from a native DS
datatype"

could anyone help me with this please. i already passed two days trying to
figure out what is the problem.

thank you very much

the code is in J#

/**************************************************/



private System.DirectoryServices.DirectoryEntry root;

private System.DirectoryServices.DirectorySearcher ds;

private System.DirectoryServices.SearchResultCollection src;

private System.DirectoryServices.SearchResult result;

private System.DirectoryServices.DirectoryEntry user;

root = new
System.DirectoryServices.DirectoryEntry(LDAP_ROOT,LDAP_NAME,LDAP_PASS);

ds = new System.DirectoryServices.DirectorySearcher(root);

ds.set_CacheResults(true);

ds.set_Filter("(&(objectCategory=Person)(objectClass=user))");

src = ds.FindAll();

for(int i=0 ;i<totalRows ;i++)

{


result = (System.DirectoryServices.SearchResult) src.get_Item(i);

user = result.GetDirectoryEntry();

if(user != null)

{

user.get_Properties().get_Item("givenName").get_Value().ToString();

}

}
 
I am trying to retrieve the users of the company using active directory.
When i execute the code below , it gives the following error

"The Active Directory datatype cannot be converted to/from a native DS
datatype"

could anyone help me with this please. i already passed two days trying to
figure out what is the problem.

Well, if you do a search using DirectorySearcher, you should specify
which attributes you're interested in, so that those will be retrieved
for each of your resulting objects. This saves you from having to go
back to the full DirectoryEntry for each search result (saving you at
least one network roundtrip).

This is in C# - should be easy enough to translate into J#:

DirectorySearcher ds = new DirectorySearcher(root);
ds.Filter = "(&(objectCategory=Person)(objectClass=user))";

ds.PropertiesToLoad.Add("givenName");
// add any other properties you're interested in!

foreach(SearchResult oRes in ds.FindAll() )
{
Console.WriteLine(oRes.Properties["givenName"].Value);
}

Marc
================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top