G
Guest
I am trying to populate a drop down box with the query of users from Active
Directory. The query is working fine but the data that shows up in the
dropdown box is "System.DirectoryServices.Searchreult". Here is the code:
Anys suggestions anyone?
Protected Sub btnFindUser_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnFindUser.Click
Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
Dim rootString As New String("LDAP://" +
objRootDSE.Properties("defaultNamingContext").Value)
Dim root As New DirectoryEntry(rootString)
Dim objSearch As New DirectorySearcher(root)
Dim oResults As SearchResultCollection
Dim oresult As SearchResult
Try
objSearch.Filter = "(&(objectCategory=Person)(sn=" +
txtLastName.Text + "))"
objSearch.PropertiesToLoad.Add("ADsPath")
objSearch.PropertiesToLoad.Add("displayName")
oResults = objSearch.FindAll()
lblresultsCount.Text = oResults.Count
drpUsersFound.DataSource = oResults
drpUsersFound.DataBind()
For Each oresult In oResults
If Not oresult.GetDirectoryEntry().Properties("cn").Value =
"" Then
drpUsersFound.DataValueField =
oresult.GetDirectoryEntry().Properties("adspath").Value
Dim temp1 As String = oresult.Properties("adsPath")(0)
Dim temp2 As String = oresult.Properties("displayName")(0)
drpUsersFound.DataTextField =
oresult.GetDirectoryEntry().Properties("displayname").Value
lblName.Text =
oresult.GetDirectoryEntry().Properties("displayname").Value
End If
Next
drpUsersFound.Visible = True
Label2.Visible = True
Catch ex As Exception
Console.WriteLine("the error is " + ex.ToString())
End Try
End Sub
End Class
Directory. The query is working fine but the data that shows up in the
dropdown box is "System.DirectoryServices.Searchreult". Here is the code:
Anys suggestions anyone?
Protected Sub btnFindUser_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnFindUser.Click
Dim objRootDSE As New DirectoryEntry("LDAP://RootDSE")
Dim rootString As New String("LDAP://" +
objRootDSE.Properties("defaultNamingContext").Value)
Dim root As New DirectoryEntry(rootString)
Dim objSearch As New DirectorySearcher(root)
Dim oResults As SearchResultCollection
Dim oresult As SearchResult
Try
objSearch.Filter = "(&(objectCategory=Person)(sn=" +
txtLastName.Text + "))"
objSearch.PropertiesToLoad.Add("ADsPath")
objSearch.PropertiesToLoad.Add("displayName")
oResults = objSearch.FindAll()
lblresultsCount.Text = oResults.Count
drpUsersFound.DataSource = oResults
drpUsersFound.DataBind()
For Each oresult In oResults
If Not oresult.GetDirectoryEntry().Properties("cn").Value =
"" Then
drpUsersFound.DataValueField =
oresult.GetDirectoryEntry().Properties("adspath").Value
Dim temp1 As String = oresult.Properties("adsPath")(0)
Dim temp2 As String = oresult.Properties("displayName")(0)
drpUsersFound.DataTextField =
oresult.GetDirectoryEntry().Properties("displayname").Value
lblName.Text =
oresult.GetDirectoryEntry().Properties("displayname").Value
End If
Next
drpUsersFound.Visible = True
Label2.Visible = True
Catch ex As Exception
Console.WriteLine("the error is " + ex.ToString())
End Try
End Sub
End Class