Estoy haciendo una prueba con . net para infopath
existe 1 forma, doy click a un boton , consulto los datos del usuario en el dominio
lleno la informacion en la forma. funciona, poopula las variables, pero al momento de escribir en infopath , me aparece un error
"referencia a Objeto no establecida como instancia de un objeto"
Anexo el Codigo , espero puedan ayudarme
Public Sub CTRL28_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
Try
' Get the user name of the current user.
Dim userName As String = Me.Application.User.UserName
' Create a DirectorySearcher object using the user name
' as the LDAP search filter. If using a directory other
' than Exchange, use sAMAccountName instead of mailNickname.
Dim searcher As DirectorySearcher = New DirectorySearcher( _
"(mailNickname=" + userName + ")")
' Search for the specified user.
Dim result As SearchResult = searcher.FindOne()
' Make sure the user was found.
If result Is Nothing Then
MessageBox.Show("Error finding user: " + userName)
Else
' Create a DirectoryEntry object to retrieve the collection
' of attributes (properties) for the user.
Dim employee As DirectoryEntry = result.GetDirectoryEntry()
' Assign the specified properties to string variables.
Dim FirstName As String = employee.Properties( _
"givenName").Value.ToString()
Dim LastName As String = employee.Properties( _
"sn").Value.ToString()
Dim Mail As String = employee.Properties( _
"mail").Value.ToString()
Dim Location As String = employee.Properties( _
"physicalDeliveryOfficeName").Value.ToString()
Dim Title As String = employee.Properties( _
"title").Value.ToString()
Dim Phone As String = employee.Properties( _
"telephoneNumber").Value.ToString()
Dim Department As String = employee.Properties( _
"department").Value.ToString()
' The manager property returns a distinguished name,
' so get the substring of the common name following "CN=".
'Dim ManagerName As String = employee.Properties( _
' "manager").Value.ToString()
'ManagerName = ManagerName.Substring( _
' 3, ManagerName.IndexOf(",") - 3)
' Create an XPathNavigator to walk the main data source
' of the form.
Dim xnMyForm As XPathNavigator = Me.CreateNavigator()
Dim ns As XmlNamespaceManager = Me.NamespaceManager
' Set the fields in the form. ******AQUI ABAJO ES DONDE ME MANDA EL ERROR"******* xnMyForm.SelectSingleNode("/my:myFields/my:FirstName", ns) _
.SetValue(FirstName)
xnMyForm.SelectSingleNode("/my:myFields/my:LastName", ns) _
.SetValue(LastName)
xnMyForm.SelectSingleNode("/my:myFields/my:Alias", ns) _
.SetValue(userName)
xnMyForm.SelectSingleNode("/my:myFields/my:Email", ns) _
.SetValue(Mail)
'xnMyForm.SelectSingleNode("/my:myFields/my:Manager", ns) _
'.SetValue(ManagerName)
'xnMyForm.SelectSingleNode("/my:myFields/my:Location", ns) _
'.SetValue(Location)
xnMyForm.SelectSingleNode("/my:myFields/my:Title", ns) _
.SetValue(Title)
xnMyForm.SelectSingleNode("/my:myFields/my:TelephoneNumber", _
ns).SetValue(Phone)
xnMyForm.SelectSingleNode("/my:myFields/my:Department", ns) _
.SetValue(Department)
' Clean up.
xnMyForm = Nothing
searcher.Dispose()
result = Nothing
employee.Close()
End If
Catch ex As Exception
MessageBox.Show("The following error occurred: " + _
ex.Message.ToString())
Throw
End Try
End Sub