Pass arguments into InfoPath 2007 from commandline / MOSS form services

When I design forms it is interesting to know if the form is running on a client or renderd on a server (MOSS Forms services / Forms Server).

If you have this information you can customize some special features only available on the client or on the web. As you know InfoPath client is not the same as form services. Not all features work on the web.

Beside the startup location it is interesting how to pass arguments to the form. It is possible to pass arguments from commandline or from web.

If you follow this rule and you are care with your source code you have maximum on flexibility within your form. Try to make sure that your form works on client and web well.

You can download my form or create it yourself. To run my sample create a new form and put following elements inside

The data source should look like this (Case sensitive)

The form should look like this

If you call your form from command line
infopath.exe „c:\startUp.xsn“ /InputParameters „value1=valueA&value2=valueB“

If you call your from from MOSS this will be different. Change all values within the angle bracket.

If you call and want to open your form within the client just call this URL


If you call and want to open in WEB you have two possibilities

The form is new


The form already exists



Put following code in the FormEvents_Loading section


string value1 = String.Empty;
string value2 = String.Empty;

XPathNavigator xPathNavi = MainDataSource.CreateNavigator();
XPathNavigator xStartLocation = xPathNavi.SelectSingleNode(„/my:Root/my:startLocation“, this.NamespaceManager);
XPathNavigator xFirstArgument = xPathNavi.SelectSingleNode(„/my:Root/my:firstArgument“, this.NamespaceManager);
XPathNavigator xSecondArgument = xPathNavi.SelectSingleNode(„/my:Root/my:secondArgument“, this.NamespaceManager);

// check input arguments
if (e.InputParameters.ContainsKey(„value1“) && e.InputParameters.ContainsKey(„value2“))

value1 = e.InputParameters[„value1“].ToString().Trim();
value2 = e.InputParameters[„value2“].ToString().Trim();



// check if form is called on client or forms services
if (String.IsNullOrEmpty(this.Template.Uri.Host))
     xStartLocation.SetValue(„Called on client“);
     xStartLocation.SetValue(„Called on forms services“);


Download the form here IPFStartUpSample

This code won’t work in InfoPath 2003.


Dieser Beitrag wurde unter Development, Infopath veröffentlicht. Setze ein Lesezeichen auf den Permalink.