Share via


User.UserName Property (Microsoft.Office.InfoPath)

Gets only the user's username.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

Syntax

'Declaration
Public MustOverride ReadOnly Property UserName As String
'Usage
Dim instance As User
Dim value As String

value = instance.UserName
public abstract string UserName { get; }

Property Value

The user's username.

Remarks

When the form is opened in InfoPath, calling the UserName property is equivalent to calling System.Environment.UserName.

When the form is deployed to and opened from Microsoft Office Forms Server 2007 or from an appropriately configured document library in Microsoft Office SharePoint Server 2007 running InfoPath Forms Services, calling the UserName property is equivalent to calling the SharePoint SPUser.Name property. This can be different from calling SPUser.LoginName if the administrator decides to change the display name of the user. If you want to get to the actual account used to connect to the site you will have to use the LoginName property.

Note

The Local Intranet zone permissions allow reading the username from the environment, so this method can be called by domain-based form templates.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed from code running in forms opened in Microsoft Office InfoPath 2007 or in a Web browser.

Example

In the following example, clicking the Button control displays the current user's username only.

public void CTRL1_Clicked(object sender, ClickedEventArgs e)
{
   MessageBox.Show(this.Application.User.UserName);
}
Public Sub CTRL1_Clicked(ByVal sender As Object, _
   ByVal e As ClickedEventArgs)
   MessageBox.Show(Me.Application.User.UserName)
End Sub

See Also

Reference

User Class
User Members
Microsoft.Office.InfoPath Namespace