How to Populate Current User in Form Without Needing a Code Signing Certificate


Folks,


On my Blog I have two code samples that talk about pulling the Current User information based on the user's authentication to Active Directory and populating it into a form.   One sample uses JScript and the other uses VB.Net.    The JScript sample requires that the solution be signed with a Level 2 code signing certificate.    Alternatively you can deploy the solution as an MSI using a tool in the Resource Kit, but that turns out to be somewhat problematic over time (breaks slick deployment and update model).   I'm not sure about the second VB.Net sample, I haven't tested it myself and so not sure 100% how it works and what might be needed to have that code run.   I do know of another code sample that uses C# to do the same thing, and I have tested it and it works without requiring a signing cert.    That code and the walkthough on how to use it is here http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_ip2003_tr/html/odc_INF_Lab_15.asp.    For the benefit of the Blog, the actual code you need is here:


// store an XMLDOM node as a local variable
IXMLDOMNode nodeEmployee =
thisXDocument.DOM.selectSingleNode("my:myFields/my:employee");
if(nodeEmployee != null){
      if(nodeEmployee.text == ""){
         // if the employee name is blank when we load the form,
         // populate the employee node with the current user name
nodeEmployee.text = System.Environment.UserName;
}
}


Pretty simple, huh?


Tim

Comments (4)
  1. Bob_Chauvin says:

    System.Environment.UserName requires Full trust, or more precisely a

    permission that only Full trust forms would get.

    Note that System.Environment.UserName will not return the real WSS user

    name, which I assume your code actually needs. Instead, we recommend using

    the InfoPath OM to get the user name.

  2. Bob_Chauvin says:

    System.Environment.UserName requires Full trust, or more precisely a

    permission that only Full trust forms would get.

    Note that System.Environment.UserName will not return the real WSS user

    name, which I assume your code actually needs. Instead, we recommend using

    the InfoPath OM to get the user name.

  3. hype8912 says:

    When trying to use the above code I always get an error when trying to preview the form.  I’ve tried putting a semi-colon everywhere to include removing all the semi-colons. I commented out each line, one at a time and found that its dieing on:

    IXMLDOMNode nodeEmployee =

    thisXDocument.DOM.selectSingleNode("my:myFields/my:employee");

    InfoPath cannot open the selected form because of an error in the form’s code.

    The following error occurred:

    Expected ‘;’

    File:script.js

    Line:48

    IXMLDOMNode nodeEmployee =

    Any ideas?

  4. slescure says:

    Hum- this post is great – just what I need to do.  

    But…

    I need to do it using VB.NET – the text above seem to imply that there is a sample in VB, but from I don’t see it.  It seems to be written in C#.  Does the VB sample exist anywhere else?

    thanks!

Comments are closed.

Skip to main content