I'm creating an Infopath form and I need to query Active Directory to obtain
some data. Here is the code I'm using (obtained from sample code from MSDN)
Private Shared domainADsPath As String = "LDAP://xxx.com"
Private Shared username As String = "gary"
Private Shared password As String = "password"
Private Shared schemaClassName ToSearch As String = "user"
Sub Lookup
Dim strUserName as String
Dim searcher As New DirectorySearch er()
searcher.Search Root = New DirectoryEntry( domainADsPath, username,
Password)
searcher.Filter = "(objectCla ss=" + schemaClassName ToSearch + ")"
searcher.Search Scope = SearchScope.Sub tree
searcher.Sort = New SortOption("nam e", SortDirection.A scending)
searcher.Proper tiesToLoad.AddR ange(New String() {"displayNam e", "name"})
Dim result As SearchResult
result = searcher.FindOn e()
If Not (result Is Nothing) Then
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal Coll As ResultPropertyV alueCollection
myResultPropCol l = result.Properti es
myResultPropVal Coll = myResultPropCol l.Item("name")
strUserName = myResultPropVal Coll.Item(0).To String()
thisXDocument.D OM.selectSingle Node("//my:Name").text = strUserName
Else
thisXDocument.D OM.selectSingle Node("//my:Name").text = "Not Found"
End If
What displays on the form is the object name
(ie. System.Director yServices.Resul tPropertyValueC ollection), not the value
of the property. All of the classes return an object and not a string. How do
I return the actual value of the property?
Thanks for the help!
--
Gary
some data. Here is the code I'm using (obtained from sample code from MSDN)
Private Shared domainADsPath As String = "LDAP://xxx.com"
Private Shared username As String = "gary"
Private Shared password As String = "password"
Private Shared schemaClassName ToSearch As String = "user"
Sub Lookup
Dim strUserName as String
Dim searcher As New DirectorySearch er()
searcher.Search Root = New DirectoryEntry( domainADsPath, username,
Password)
searcher.Filter = "(objectCla ss=" + schemaClassName ToSearch + ")"
searcher.Search Scope = SearchScope.Sub tree
searcher.Sort = New SortOption("nam e", SortDirection.A scending)
searcher.Proper tiesToLoad.AddR ange(New String() {"displayNam e", "name"})
Dim result As SearchResult
result = searcher.FindOn e()
If Not (result Is Nothing) Then
Dim myResultPropCol l As ResultPropertyC ollection
Dim myResultPropVal Coll As ResultPropertyV alueCollection
myResultPropCol l = result.Properti es
myResultPropVal Coll = myResultPropCol l.Item("name")
strUserName = myResultPropVal Coll.Item(0).To String()
thisXDocument.D OM.selectSingle Node("//my:Name").text = strUserName
Else
thisXDocument.D OM.selectSingle Node("//my:Name").text = "Not Found"
End If
What displays on the form is the object name
(ie. System.Director yServices.Resul tPropertyValueC ollection), not the value
of the property. All of the classes return an object and not a string. How do
I return the actual value of the property?
Thanks for the help!
--
Gary