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 / .NET Framework / General / September 2005

Tip: Looking for answers? Try searching our database.

Populating drop down list from AD

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Geier - 29 Sep 2005 20:40 GMT
string strLdap = "LDAP://OU=Sales,DC=Company,DC=com"
DirectoryEntry objOU = new DirectoryEntry(strLdap);
DirectorySearcher objUserSearcher = new DirectorySearcher(objOU);
SearchResultCollection objResults;
//Search for user objects
objUserSearcher.PropertiesToLoad.Add("cn");
objUserSearcher.Filter = "(objectClass=user)";
objResults = objUserSearcher.FindAll();
DropDownList1.Items.Add("New User");
//Loop through the search results adding each one to the combo box
foreach (SearchResult objResult in objResults)
DropDownList1.Items.Add(objResult.Properties["cn"][0]);

What am I doing wrong here...
CT - 30 Sep 2005 07:21 GMT
This works for me:

        string strLdap =
"LDAP://serverName/CN=Users,OU=Sales,DC=Company,DC=com";
        DirectoryEntry objOU = new DirectoryEntry(strLdap, "userName",
"password");
        DirectorySearcher objUserSearcher = new DirectorySearcher(objOU,
"(&(objectClass=user)(objCategory=person))");
        SearchResultCollection objResults;
        //Search for user objects
        objUserSearcher.PropertiesToLoad.Add("cn");
        objResults = objUserSearcher.FindAll();
        DropDownList1.Items.Add("New User");
        //Loop through the search results adding each one to the combo box
        foreach (SearchResult objResult in objResults)
           DropDownList1.Items.Add(objResult.Properties["cn"][0]);

Signature

Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

> string strLdap = "LDAP://OU=Sales,DC=Company,DC=com"
> DirectoryEntry objOU = new DirectoryEntry(strLdap);
[quoted text clipped - 10 lines]
>
> What am I doing wrong here...
CT - 30 Sep 2005 08:26 GMT
Oops, to hasty in copying and pasting; replace this line

DirectorySearcher objUserSearcher = new DirectorySearcher(objOU,
"(&(objectClass=user)(objCategory=person))");

with

DirectorySearcher objUserSearcher = new DirectorySearcher(objOU,
"(objectClass=user)");

or simply use
DirectorySearcher objUserSearcher = new DirectorySearcher(objOU);
and add the Filter you were using in your own code snippet.

Signature

Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

> This works for me:
>
[quoted text clipped - 27 lines]
>>
>> What am I doing wrong here...
Chris Geier - 30 Sep 2005 18:11 GMT
I can get this to work perfectly in a winform. But when I want to do it from
a webform it does not work. I am getting 2 error messages focused on the last
line of code

The best overloaded method match for
'system.web.ui.webcontrols.listitemcollection.Add(string)' has some invalid
arguements

and secondly

Arguement 1 cannot convert from object to string.
John Bailo - 30 Sep 2005 18:15 GMT
It expects an object, whose value is type string.

Example:

listBoxData.Add(New ListItem("apples"))

Source:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlr
fsystemwebuiwebcontrolslistitemcollectionclassaddtopic.asp


> I can get this to work perfectly in a winform. But when I want to do it from
> a webform it does not work. I am getting 2 error messages focused on the last
[quoted text clipped - 7 lines]
>
> Arguement 1 cannot convert from object to string.

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



©2008 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.