Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Services / December 2005

Tip: Looking for answers? Try searching our database.

Active Directory OU Retreival

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
multisync - 08 Dec 2005 00:12 GMT
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?
Marc Scheuner - 08 Dec 2005 06:24 GMT
>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 - 08 Dec 2005 16:22 GMT
Yes, its something like that.

> >I have an OU called "Sites"
>
[quoted text clipped - 46 lines]
> Hope this helps
> Marc

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.