Passing Parameters to an InfoPath 2007 Browser Form

Microsoft Office InfoPath 2007 supports parameters for browser forms. This functionality can make form solutions more dynamic and requires only a small amount of code. Within the Loading event of the form template, the TryGetValue method is needed for each parameter value that is being passed. Then, the appropriate fields in the form file can be set accordingly. The following C# code sample shows how the building permit application solution can be extended with a LotNumber parameter.

public void FormEvents_Loading(object sender, LoadingEventArgs e)
    string lotNumber = string.Empty;
        e.InputParameters.TryGetValue("LotNumber", out lotNumber);
    catch (Exception ex)
        lotNumber = ex.Message.ToString();
        MainDataSource.CreateNavigator().SelectSingleNode("//my:LotNumber", NamespaceManager).SetValue(lotNumber);

In this example, the LotNumber value is passed to the form from the browser URL. It is also worth noting that the parameter names are case-sensitive, as shown in the following figure:

5 thoughts on “Passing Parameters to an InfoPath 2007 Browser Form

  1. Does LoadingEventArgs.InputParameters also look in the POST data? That is, if FormServer.aspx is even designed to render a form when getting a POST rather than a GET.

    Is LoadingEventArgs documented anywhere yet?


  2. Thanks for your reply. FormServer.aspx seems to handle POSTs fine, and up the callstack I see an HttpContext parameter, and I can see the data I passed in by using the Immediate window. But I can’t access it from the stack frame of the Loading event (there may be some hacks to go up the call stack programatically, but I would rather avoid that).

    On a related note, is there a simple way to prepopulate the form by overwriting its entire xml based on an Xml string passed in? I tried setting navigator.OuterXml but I get this InvalidOperationException:

    Additional information: Operation is not valid due to the current position of the navigator.

    Any help is appreciated. Thanks, Radu

  3. Hi, Radu.

    You might want to try selecting the root node, removing all children with the RemoveAll method, and then adding your XML to the root with the AppendChild method. At least that’s one way of replacing the XML content…

    That’s good info regarding the POSTs. If I hear back from the InfoPath team, I will post a follow-up.


  4. Thanks for the feedback. Yes, I think that having access to POST data is important, as the QueryString is restricted to about 2k. I think quite a few FormsServer users will be interested in passing the entire form Xml to easily prepopulate it, and that can’t be done via the QueryString.

    A temporary solution would be to pass in a Guid and have the Loading event call back and ask for the full xml, but that is more convoluted and adds to the latency in loading the form, which may lead some end users to incorrectly think that FormsServer is slow. So exposing the HttpContext (or at least HttpContext.Form) would be very useful.

  5. Hi, Radu.

    Your questions about POST data are good ones that I have forwarded on to the InfoPath development team. With the previous version of InfoPath, Brandon Paddock’s post ( seemed to be a good resource for using parameters with form templates. Note, however, that his solution is not intended for browser scenarios.

    Regarding LoadingEventArgs, I am not aware of any documentation that has been posted.


Comments are closed.