The problem: Most usernames show up in the dropdownlist, but a random
few do not show up. Why? If I put the filter below into my Users and
Computers snap-in as an advanced search, it finds all of them.
Here's the meat of the ldap search:
Private Function GetUsernames() As DataTable
Dim rootEntry As New DirectoryEntry("LDAP://" &
ConfigurationManager.AppSettings("FQDN"))
Dim searcher As New DirectorySearcher(rootEntry)
searcher.SearchScope = SearchScope.Subtree
searcher.Filter =
"(&(ObjectClass=user)(ObjectCategory=person))"
searcher.PropertiesToLoad.Add("samAccountName")
Dim srcResults As SearchResultCollection = searcher.FindAll()
Dim srResult As SearchResult
Dim rpcPropertyCollection As ResultPropertyCollection
Dim objMember As Object
Dim myDataTable As New DataTable("dtUsers")
Dim dcUserName As New DataColumn("UserName", GetType(String))
myDataTable.Columns.Add(dcUserName)
For Each srResult In srcResults
Dim dr As DataRow
dr = myDataTable.NewRow()
dr("UserName") =
CType(srResult.Properties("samAccountName")(0), String)
myDataTable.Rows.Add(dr)
Next
myDataTable.DefaultView.Sort = "UserName"
Return myDataTable
End Function
This is the binding of the datalist containing the column with
dropdownlists of usernames.
Private Sub BindSearchResultsDataList()
Dim myDataListItem As DataListItem
Dim strFirstName, strLastName As String
strFirstName = txtFirstName.Text
strLastName = txtLastName.Text
strFirstName = Replace(strFirstName, "'", "''")
strLastName = Replace(strLastName, "'", "''")
Dim connectionString As String = DecryptConnectionString()
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = "BLANKED OUT SELECT QUERY"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open()
Dim myReader As SqlDataReader
myReader = dbCommand.ExecuteReader()
dlSearchResults.DataSource = myReader
dlSearchResults.DataBind()
If dlSearchResults.Items.Count <> "0" Then
dlSearchResults.Visible = True
Else
dlSearchResults.Visible = False
lblSearchResult.Text = "No employees found."
End If
dbConnection.Close()
Dim dtUsernames As DataTable = GetUsernames()
For Each myDataListItem In dlSearchResults.Items
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataSource = dtUsernames
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataTextField = "Username"
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataValueField = "Username"
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataBind()
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).Items.Insert(0, "")
Next
End Sub
---------------------------------------------------------------------- 1 1309
Joe K. solved my problem! The answer was using searcher.pagesize. By
default, the query is limited to 1000 results to prevent DOS attacks. fu*********@gmail.com wrote:
The problem: Most usernames show up in the dropdownlist, but a random
few do not show up. Why? If I put the filter below into my Users and
Computers snap-in as an advanced search, it finds all of them.
Here's the meat of the ldap search:
Private Function GetUsernames() As DataTable
Dim rootEntry As New DirectoryEntry("LDAP://" &
ConfigurationManager.AppSettings("FQDN"))
Dim searcher As New DirectorySearcher(rootEntry)
searcher.SearchScope = SearchScope.Subtree
searcher.Filter =
"(&(ObjectClass=user)(ObjectCategory=person))"
searcher.PropertiesToLoad.Add("samAccountName")
Dim srcResults As SearchResultCollection = searcher.FindAll()
Dim srResult As SearchResult
Dim rpcPropertyCollection As ResultPropertyCollection
Dim objMember As Object
Dim myDataTable As New DataTable("dtUsers")
Dim dcUserName As New DataColumn("UserName", GetType(String))
myDataTable.Columns.Add(dcUserName)
For Each srResult In srcResults
Dim dr As DataRow
dr = myDataTable.NewRow()
dr("UserName") =
CType(srResult.Properties("samAccountName")(0), String)
myDataTable.Rows.Add(dr)
Next
myDataTable.DefaultView.Sort = "UserName"
Return myDataTable
End Function
This is the binding of the datalist containing the column with
dropdownlists of usernames.
Private Sub BindSearchResultsDataList()
Dim myDataListItem As DataListItem
Dim strFirstName, strLastName As String
strFirstName = txtFirstName.Text
strLastName = txtLastName.Text
strFirstName = Replace(strFirstName, "'", "''")
strLastName = Replace(strLastName, "'", "''")
Dim connectionString As String = DecryptConnectionString()
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionStri ng)
Dim queryString As String = "BLANKED OUT SELECT QUERY"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection
dbConnection.Open()
Dim myReader As SqlDataReader
myReader = dbCommand.ExecuteReader()
dlSearchResults.DataSource = myReader
dlSearchResults.DataBind()
If dlSearchResults.Items.Count <"0" Then
dlSearchResults.Visible = True
Else
dlSearchResults.Visible = False
lblSearchResult.Text = "No employees found."
End If
dbConnection.Close()
Dim dtUsernames As DataTable = GetUsernames()
For Each myDataListItem In dlSearchResults.Items
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataSource = dtUsernames
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataTextField = "Username"
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataValueField = "Username"
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataBind()
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).Items.Insert(0, "")
Next
End Sub
----------------------------------------------------------------------
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Eric McIntyre |
last post by:
I am using DB2 UDB 8.1. Can I add users to the database that have dots
in their usernames (firstname.lastname)?
Thanks
Eric
|
by: NG WEI CHUNG |
last post by:
Hi,
Some of my clients site is unable to view the ASP .NET page due to the
proxy server and firewall or perhaps IE setting etc, I m not sure what is the
actual cause of the problem, it display...
|
by: Joe |
last post by:
Hi,
A part of our ASP website is password protected. People need to create
accounts in order to gain access to the secured website. The username is
email. After the user logs in a session cookie...
|
by: Microsoft |
last post by:
Hello all I am new to 2003 server and Active Directory, I want to put
spaces in the usernames for the domain users. Now my question is will that
create any problems in the future with anything...
|
by: Brad |
last post by:
I have a win2003 server workstation with multiple webs, each web has it's
own ip address. In VS2005, if I select to open an existing web site, select
Local IIS, the dialog correctly displays a...
| |
by: Henry Stockbridge |
last post by:
Hi,
I am attempting to incorporate Dev Ashish's fOSUserName code with
multiple UserNames but come up with a runtime error (13) / Type
mismatch. Any help you can lend would be appreciated. Here...
|
by: npaulus |
last post by:
Hi,
I am trying to list all usernames from active directory under the
domain 'tefter.com'
DirectoryEntry entry = new DirectoryEntry();
DirectorySearcher mySearcher = new...
|
by: mvsguy |
last post by:
I'm an Access noob and apologize if I'm asking a stupid question. The
problem is that I'm unable to design/preview reports on a database.
How do I go about fixing this?
Background -
A user has...
|
by: Markw |
last post by:
Hi folks I think I've got a variable problem but not 100% sure.
Background: I took the CMS example from chapter 6 in "Build your Own Database Driven Website Using PHP&MySQL" and have attempted to...
|
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,...
|
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...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |