LDAP connection help DirectoryService Information ?? RRS feed

  • Question

  • User-1831219222 posted


    I have a textbox. When I type the name in this textbox the related information should be popup from the 'DirectoryServices' look up.

    I use this code below and I have some error:

    DirectoryEntry publicDir = new DirectoryEntry(LDAP://mydomain/OU=..,DC=metadirectory,DC=..,DC=..,DC=..);

    <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>for (int i = 97; i <= 122; i++)


    <o:p></o:p>string firstLetter = Convert.ToChar(i).ToString();


    <o:p></o:p>DirectorySearcher ds = new DirectorySearcher(publicDir, "(&(departmentnumber=xxxx)(sn=" + firstLetter + "*))");


    <o:p></o:p>SearchResultCollection coll = ds.FindAll();


    <o:p></o:p>foreach (SearchResult sr in coll)<o:p></o:p>{


    <o:p></o:p>DirectoryEntry dr = sr.GetDirectoryEntry();


    response.writeline(dr.Properties["sn"].Value + " " + dr.Properties["givenname"].Value);<o:p></o:p>dr.Dispose();<o:p></o:p>}<o:p></o:p>}<o:p></o:p>publicDir.Dispose();<o:p></o:p> 


    <o:p></o:p><o:p> </o:p>The error is:<o:p></o:p><o:p> </o:p>no overload for method ‘DictionaryEntry’ takes 1 arguments- in the first line of code:


    <o:p></o:p>DirectoryEntry publicDir = new DirectoryEntry(LDAP://mydomain/OU=..,DC=metadirectory,DC=..,DC=..,DC=..);


    <o:p></o:p>And can’t convert from ‘system.collections.DictionaryEntry’ to ’system.DirectoryServices.DictionaryEntry’ in this line:


    <o:p></o:p>DirectorySearcher ds = new DirectorySearcher(publicDir, "(&(departmentnumber=xxxx)(sn=" + firstLetter + "*))");<o:p></o:p>


    Any help will be highly appreciated.



    Tuesday, February 17, 2009 5:15 PM

All replies

  • User-1682309430 posted

    The error suggests that you might be using "DictionaryEntry" instead of "DirectoryEntry" some where in the source file. Verify. It may solve the issue.

    Wednesday, February 18, 2009 2:53 AM
  • User-1831219222 posted

    I updated my code:

    protected void Button1_Click(object sender, EventArgs e)


    str = txtID.Text;


    DirectoryEntry publicDir = new DirectoryEntry("LDAP://domain/OU=people,DC=metadirectory,DC=..,DC=...,DC=edu");


    DirectorySearcher ds = new DirectorySearcher(publicDir, "(id=" + str + ")");


    SearchResultCollection coll = ds.FindAll();


    foreach (SearchResult sr in coll)


    DirectoryEntry dr = sr.GetDirectoryEntry();

    StringDictionary stDir = new StringDictionary();


    foreach (string key in dr.Properties)


    stDir.Add(key, dr.Properties[key].ToString());


    GridView1.DataSource = stDir;








    Now the problem is:

    System.Runtime.InteropServices.COMException: The specified directory service attribute or value does not exist.

    in this line

    SearchResultCollection coll = ds.FindAll();


    Any help will be highly appreciated.





    Wednesday, February 18, 2009 2:01 PM
  • User773050858 posted

    The error specifies that the root directory object and/or its children doesnt have such attribute/value pair i.e. the (id="value") pair. To make successful search use the correct attribute names. Verify which attribute you have to compare and get the result.

    Hope this helps!

    Thursday, February 19, 2009 3:26 AM