473,396 Members | 2,018 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Populating drop down list from AD

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...
Sep 29 '05 #1
4 6366
CT
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]);
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Chris Geier" <chris.geier at gmail.com> wrote in message
news:CC**********************************@microsof t.com...
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...

Sep 30 '05 #2
CT
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.
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"CT" <ca******@spammersgoawaydotnetservices.biz> wrote in message
news:Ov**************@TK2MSFTNGP09.phx.gbl...
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]);
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Chris Geier" <chris.geier at gmail.com> wrote in message
news:CC**********************************@microsof t.com...
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...


Sep 30 '05 #3
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.
Sep 30 '05 #4

It expects an object, whose value is type string.

Example:

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

Source:

http://msdn.microsoft.com/library/de...ssaddtopic.asp

Chris Geier wrote:
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.

Sep 30 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Deb | last post by:
I am having a problem creating a form in Access 2000 which I have done with no problem in 97. I have an unbound drop down box. This idea is for the user to select from the drop down box and the...
1
by: lewindha | last post by:
Hey guys I'm trying to populate a drop down list with values from a db table. When I view the page, the drop list is empty. Here is the code: private void populateClients() { string...
6
by: Casey | last post by:
hello, I need to populate a drop down list when the user clicks on the arrow button. how do i do this. Should i use a html select control or is it possible using the asp:dropdownlist
1
by: msnews.microsoft.com | last post by:
I'd like to hear your thoughts on best methods for populating drop down list controls. I have states and countries drop down lists that don't change often, so naturally I "hard code" them in the...
5
by: TB | last post by:
Hi All: The following is probably a newbie question, but please bear with me: I am populating a drop down list with items from a database, and would the default selected item to be the current...
4
by: Pete Lux | last post by:
I have a drop down that populates on page load. The drop down brings in customer numbers from my local MSDE database. It does this fine, but I click a button that finds quotes for those customers...
2
by: Jim in Arizona | last post by:
My goal, somehow, is to populate a dropdownlist with all the user names in active directory. I don't even know where to begin, really. I added a reference to System.DirectoryServices so I could...
6
by: Rob Meade | last post by:
Hi all, Looking for a bit of help if possible. For about 2 weeks now I've been investigating the best way to populate related drop down menus, and have their values pre-populated again if the...
3
by: DaveRook | last post by:
Hi I am using C# and Access databse for a web site. I have a drop down list which I need to populate dynamically according to results in a database. Example There will be 1 drop down list...
14
by: Philth | last post by:
Hi there, I've essentially got a form with several drop down, each populated by columns in various tables. The populating bit works fine - the column rows appear as they should in the menu. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.