Here is some sample code I use to populate some fields in the form...
Public Sub GetUserInformation()
Try
' Get the user name of the current user.
Dim strUserName As String = Me.Application.User.UserName
' Create a DirectorySearcher object using the user name
' as the Active Directory LDAP search filter. If using a directory other
' than Exchange, use sAMAccountName instead of mailNickname.
Dim ADsSearcher As DirectorySearcher = New
DirectorySearcher("(sAMAccountName=" + strUserName + ")")
' Search for the specified user.
Dim ADsSearchResult As SearchResult = ADsSearcher.FindOne()
' Make sure the user was found.
If ADsSearchResult Is Nothing Then
'How do you throw a messageBox in a Browser Enabled InfoPath Form
'MessageBox.Show("Error finding user: " + strUserName + " contact your site
Administrator.")
Else
' Create a DirectoryEntry object to retrieve the collection
' of attributes (properties) for the user.
Dim ADsEmployee As DirectoryEntry = ADsSearchResult.GetDirectoryEntry()
' Assign the specified properties to string variables.
Dim strName As String = ADsEmployee.Properties("cn").Value.ToString()
Dim strMail As String = ADsEmployee.Properties("mail").Value.ToString()
Dim strPhone As String =
ADsEmployee.Properties("telephoneNumber").Value.ToString()
' The manager property returns a distinguished name,
' so get the substring of the common name following "CN=".
'Dim strManagerName As String =
ADsEmployee.Properties("manager").Value.ToString()
'strManagerName = ManagerName.Substring(3, strManagerName.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.
xnMyForm.SelectSingleNode("/my:MSWORFields/my:InitiatorName",
ns).SetValue(strName)
xnMyForm.SelectSingleNode("/my:MSWORFields/my:InitiatorEmailAddress",
ns).SetValue(strMail)
xnMyForm.SelectSingleNode("/my:MSWORFields/my:InitiatorPhone",
ns).SetValue(strPhone)
' Clean up.
xnMyForm = Nothing
ADsSearcher.Dispose()
ADsSearchResult = Nothing
ADsEmployee.Close()
End If
Catch ex As Exception
'Requires System.Windows.Forms Namespace
'MessageBox.Show("The following error occurred: " + ex.Message.ToString() +
" contact your site Administrator.")
Throw
End Try
End Sub