Active Directory OU Retreival

Discussion in 'ASP .Net Web Services' started by multisync, Dec 8, 2005.

  1. multisync

    multisync Guest

    I have an OU called "Sites"

    I want to click a button called btn1 and I want to retrieve all the Sites
    under this OU into a dropdownlist Called dropdownlist1. I want to do this
    using LDAP. I'm working with a asp.net webform.

    Can someone please provide me the code?
     
    multisync, Dec 8, 2005
    #1
    1. Advertising

  2. >I have an OU called "Sites"

    Do you know the full LDAP path for that OU as well??

    It would have to be something like:

    LDAP://OU=Sites,OU=SomeOtherOU,dc=YourCompany,dc=com

    >I want to click a button called btn1 and I want to retrieve all the Sites
    >under this OU into a dropdownlist Called dropdownlist1. I want to do this
    >using LDAP. I'm working with a asp.net webform.


    Using that full LDAP path for your main "Sites" OU, you can easily set
    up a DirectorySearcher to retrieve all the sub-OU's under that OU. Do
    you want to get just the immediate children, or do you want to recurse
    down through the OU hierarchy?

    This assumes you want only the immediate children - and only of type
    "organizationalUnit":

    DirectoryEntry deMySites = new
    DirectoryEntry("LDAP://OU=Sites,OU=SomeOtherOU,dc=YourCompany,dc=com");

    DirectorySearcher dsSubOUs = new DirectorySearcher(deMySites);

    // search only immediate children - use SearchScope.Subtree for all
    // immediate children and subsequent grandchildren etc.
    dsSubOUs.SearchScope = SearchScope.OneLevel;

    // set the filter - we're only interested in OU's
    dsSubOUs.Filter = "(objectClass=organizationalUnit)";

    // set up what attributes to load - specify whatever attributes
    // you are interested in as results in your search
    dsSubOUs.PropertiesToLoad.Add("name");
    dsSubOUs.PropertiesToLoad.Add("cn");
    dsSubOUs.PropertiesToLoad.Add("dateCreated");

    // search for all matching OU's
    foreach(SearchResult oResult in dsSubOUs.FindAll())
    {
    // add the "name" attribute of the result to your combo box
    if(oResult.Properties.Contains("name"))
    {
    childOUsComboBox.Items.Add(oResult.Properties["name"][0].ToString();
    }
    }


    Hope this helps
    Marc
     
    Marc Scheuner, Dec 8, 2005
    #2
    1. Advertising

  3. multisync

    multisync Guest

    Yes, its something like that.

    "Marc Scheuner" wrote:

    > >I have an OU called "Sites"

    >
    > Do you know the full LDAP path for that OU as well??
    >
    > It would have to be something like:
    >
    > LDAP://OU=Sites,OU=SomeOtherOU,dc=YourCompany,dc=com
    >
    > >I want to click a button called btn1 and I want to retrieve all the Sites
    > >under this OU into a dropdownlist Called dropdownlist1. I want to do this
    > >using LDAP. I'm working with a asp.net webform.

    >
    > Using that full LDAP path for your main "Sites" OU, you can easily set
    > up a DirectorySearcher to retrieve all the sub-OU's under that OU. Do
    > you want to get just the immediate children, or do you want to recurse
    > down through the OU hierarchy?
    >
    > This assumes you want only the immediate children - and only of type
    > "organizationalUnit":
    >
    > DirectoryEntry deMySites = new
    > DirectoryEntry("LDAP://OU=Sites,OU=SomeOtherOU,dc=YourCompany,dc=com");
    >
    > DirectorySearcher dsSubOUs = new DirectorySearcher(deMySites);
    >
    > // search only immediate children - use SearchScope.Subtree for all
    > // immediate children and subsequent grandchildren etc.
    > dsSubOUs.SearchScope = SearchScope.OneLevel;
    >
    > // set the filter - we're only interested in OU's
    > dsSubOUs.Filter = "(objectClass=organizationalUnit)";
    >
    > // set up what attributes to load - specify whatever attributes
    > // you are interested in as results in your search
    > dsSubOUs.PropertiesToLoad.Add("name");
    > dsSubOUs.PropertiesToLoad.Add("cn");
    > dsSubOUs.PropertiesToLoad.Add("dateCreated");
    >
    > // search for all matching OU's
    > foreach(SearchResult oResult in dsSubOUs.FindAll())
    > {
    > // add the "name" attribute of the result to your combo box
    > if(oResult.Properties.Contains("name"))
    > {
    > childOUsComboBox.Items.Add(oResult.Properties["name"][0].ToString();
    > }
    > }
    >
    >
    > Hope this helps
    > Marc
    >
     
    multisync, Dec 8, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Prigozhin Roman

    DataGrid data retreival

    Prigozhin Roman, Nov 26, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    357
    Frank Oquendo
    Nov 26, 2003
  2. pendemv
    Replies:
    0
    Views:
    285
    pendemv
    Dec 12, 2008
  3. ejcosta
    Replies:
    2
    Views:
    919
    Eurico Costa
    Oct 8, 2004
  4. carlos seramos
    Replies:
    2
    Views:
    525
    carlos seramos
    Aug 1, 2003
  5. Michael T. Peterson

    [Q] How to automating data retreival from another server?

    Michael T. Peterson, Jan 19, 2004, in forum: Javascript
    Replies:
    2
    Views:
    93
    Brian Genisio
    Jan 19, 2004
Loading...

Share This Page