EDN Admin
Well-known member
<p style="margin:0in 0in 10pt <span style="font-size:small; font-family:Calibri Iâm developing an InfoPath 2007 form and need to give the current User the ability perform an AD search which will retrieve all AD entries with the same last name. I have
successfully programmed the button event with the below code to retrieve a single AD user (first AD entry) using the DirectorySearch.FindOne method but have not been able to figure out how to get the DirectorySearch.FindAll method to work.
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri Does someone know how to tweak the below code to work for the FindAll method? Or, is the FindAll method the correct search method to use obtain the results I need?
<span style="
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New" Try
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim xnMyForm <span style="color:blue As XPathNavigator =
<span style="color:blue Me.CreateNavigator()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim ns <span style="color:blue As XmlNamespaceManager =
<span style="color:blue Me.NamespaceManager
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim userName <span style="color:blue As
<span style="color:blue String = xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:Alias", ns).Value()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim frmLastName <span style="color:blue As
<span style="color:blue String = xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:LastName", ns).Value()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:green Dim frmFirstName As String = xnMyForm.SelectSingleNode("/my:myFields/my:FirstName", ns).Value()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:green; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim searcher <span style="color:blue As DirectorySearcher =
<span style="color:blue New DirectorySearcher( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:maroon "(sn=" + frmLastName + <span style="color:maroon
")")
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim result <span style="color:blue As SearchResult = searcher.FindOne()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue If result <span style="color:blue Is
<span style="color:blue Nothing <span style="color:blue Then
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:green MessageBox.Show("Error finding user: " + userName)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Else
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim employee <span style="color:blue As DirectoryEntry = result.GetDirectoryEntry()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim FirstName <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:maroon "givenName").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim LastName <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:maroon "sn").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:blue Dim Mail <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:maroon "mail").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:blue Dim Location <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:maroon "physicalDeliveryOfficeName").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:blue Dim Department <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:maroon "department").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:FirstName", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
.SetValue(FirstName)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:LastName", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
.SetValue(LastName)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style=" <span style="
xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:Alias", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" .SetValue(userName)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:Email", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" .SetValue(Mail)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:Location", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" <span style=" .SetValue(Location)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/myepartment", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" <span style=" .SetValue(Department)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:green Clean up.
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
xnMyForm = <span style="color:blue Nothing
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
searcher.Dispose()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
result = <span style="color:blue Nothing
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
employee.Close()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" <span style="color:blue End <span style="color:blue
If
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Catch ex <span style="color:blue As Exception
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" MessageBox.Show(<span style="color:maroon "The following error occurred: " + _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" ex.Message.ToString())
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Throw
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New" End<span style="font-size:10pt; font-family:"Courier New"
<span style="color:blue Try
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New"
<p style="margin:0in 0in 10pt <span style="font-size:small; font-family:Calibri Any help will be greatly appreciated,
<p style="margin:0in 0in 10pt <span style="font-size:small; font-family:Calibri Sincerely,
<p style="margin:0in 0in 10pt <span style="font-size:small; font-family:Calibri TCW
View the full article
successfully programmed the button event with the below code to retrieve a single AD user (first AD entry) using the DirectorySearch.FindOne method but have not been able to figure out how to get the DirectorySearch.FindAll method to work.
<p style="margin:0in 0in 10pt <span style="font-size:small <span style="font-family:Calibri Does someone know how to tweak the below code to work for the FindAll method? Or, is the FindAll method the correct search method to use obtain the results I need?
<span style="
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New" Try
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim xnMyForm <span style="color:blue As XPathNavigator =
<span style="color:blue Me.CreateNavigator()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim ns <span style="color:blue As XmlNamespaceManager =
<span style="color:blue Me.NamespaceManager
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim userName <span style="color:blue As
<span style="color:blue String = xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:Alias", ns).Value()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim frmLastName <span style="color:blue As
<span style="color:blue String = xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:LastName", ns).Value()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:green Dim frmFirstName As String = xnMyForm.SelectSingleNode("/my:myFields/my:FirstName", ns).Value()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:green; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim searcher <span style="color:blue As DirectorySearcher =
<span style="color:blue New DirectorySearcher( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:maroon "(sn=" + frmLastName + <span style="color:maroon
")")
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim result <span style="color:blue As SearchResult = searcher.FindOne()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue If result <span style="color:blue Is
<span style="color:blue Nothing <span style="color:blue Then
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:green MessageBox.Show("Error finding user: " + userName)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Else
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim employee <span style="color:blue As DirectoryEntry = result.GetDirectoryEntry()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim FirstName <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:maroon "givenName").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Dim LastName <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:maroon "sn").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:blue Dim Mail <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:maroon "mail").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:blue Dim Location <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:maroon "physicalDeliveryOfficeName").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:blue Dim Department <span style="color:blue As
<span style="color:blue String = employee.Properties( _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
<span style="color:maroon "department").Value.ToString()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:FirstName", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
.SetValue(FirstName)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:LastName", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style="
.SetValue(LastName)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style=" <span style=" <span style="
xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:Alias", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" .SetValue(userName)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:Email", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" .SetValue(Mail)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/my:Location", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" <span style=" .SetValue(Location)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" xnMyForm.SelectSingleNode(<span style="color:maroon "/my:myFields/myepartment", ns) _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" <span style=" .SetValue(Department)
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:green Clean up.
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
xnMyForm = <span style="color:blue Nothing
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
searcher.Dispose()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
result = <span style="color:blue Nothing
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
employee.Close()
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" <span style="color:blue End <span style="color:blue
If
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Catch ex <span style="color:blue As Exception
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" MessageBox.Show(<span style="color:maroon "The following error occurred: " + _
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style=" ex.Message.ToString())
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New" <span style="
<span style="color:blue Throw
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New" End<span style="font-size:10pt; font-family:"Courier New"
<span style="color:blue Try
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New"
<p style="margin:0in 0in 0pt; line-height:normal <span style="font-size:10pt; color:blue; font-family:"Courier New"
<p style="margin:0in 0in 10pt <span style="font-size:small; font-family:Calibri Any help will be greatly appreciated,
<p style="margin:0in 0in 10pt <span style="font-size:small; font-family:Calibri Sincerely,
<p style="margin:0in 0in 10pt <span style="font-size:small; font-family:Calibri TCW
View the full article