Getting Current User in InfoPath 2007 via C#

Folks,

Got a little code sample from a fellow watcher of Pashman's Goldmine (thanks Huseyin) on how to retreive the username of the current user via C# code.  Since all code samples are useful, I've posted it below:

public void FormEvents_Loading(object sender, LoadingEventArgs e)

{

string xpath = "/my:oneriForm/my:nameTxt";

string userName1;

XPathNavigator field1 = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager);

//string oldValue = field1.Value; // Read

string strUserName = System.Environment.UserName;

//userName1 = System.Environment.

field1.SetValue(strUserName);

// Write

In this case the user wanted the full user name too, and I advised him to try and replace the System.Environment.UserName with System.Environment.FriendlyName.   I'll let you know if that worked.