Passing Data into a Form: Input Parameters

This blog article discusses a new feature of Microsoft InfoPath 2007 that makes it possible to pass data into an InfoPath form at load time. A typical example would be retrieving records from a database for a particular user. At load time a ‘userID’ can be passed into the form. This userID can then be used to query the database and load the form with the user’s data.

Parameters can be passed into InfoPath form templates (XSNs) or InfoPath Forms (XMLs). The syntax for specifying input parameters is the same for both. This article focuses primarily on InfoPath client scenarios, but should apply for the most part to server scenarios as well.

How to Pass Parameters into an InfoPath Form:

There are two ways of launching an InfoPath form with parameters

1) URL

The syntax for passing parameters via the URL is the standard syntax for query parameters. For example:

Here two input parameters have been passed into the form namely ‘baz’ and ‘biz’. Their respective values are 1 and 2. The ‘Accessing Input Parameters in Form Code’ section talks about how these values are stored and accessed in InfoPath code.

The URL syntax can be used in a number of places like

  • Launching an InfoPath form in a browser by typing the URL into the address bar
  • Pasting the URL to a form or a form template into an email
  • Using the URL inside methods like NewFromFormTemplate, New, Open (XmlForms collection)
2) Command Line

The syntax for passing parameters via the command line is as follows:

infopath.exe “C:foobar.xml” /InputParameters “baz=1&biz=2

The switch /InputParameters is used to specify that parameters are being passed into the form, followed by the name/value pairs of input parameters.

Accessing Input Parameters in Form Code

Parameters passed into an InfoPath form template or form, are available during the Loading event as a read-only collection of name/value pairs. In order to access these parameters you will need to write code that reads from this collection. The InputParameters collection is exposed in all three InfoPath programming models – it is thus available in JScript, InfoPath 2003 SP1 managed code or InfoPath 2007 managed code. This example uses C# and the InfoPath 2007 managed object model. Syntax for the legacy models follows. The steps below outline how to add code that access the Input Parameters passed into a form.

  1. In the InfoPath designer, click on Tools menu -> Programming menu item.
  2. In the fly-out menu select the Loading event (will be On Load in older InfoPath versions).
  3. This will launch the appropriate IDE (MSE or VSTA or the Visual Studio Toolkit) with the code spit for the loading event inserted.
  4. Add the following code to access the input parameters ‘baz and ‘biz used in the examples above (example is in C# using InfoPath 2007 Managed Object Model)

public void FormEvents_Loading(object sender, LoadingEventArgs e)


   // Assign the value of the parameter ‘baz’ to the string ‘bazValue’. bazValue = 1

   string bazValue = e.InputParameters[“baz”];


   // Assign the value of the parameter ‘biz’ to the string ‘bizValue’. bi000zValue = 1

   string bizValue = e.InputParameters[“biz”];


   // Code that uses the parameters passed in to do whatever needs to be done

   // Example would be to create a custom query using these values and populate a table based

   // on the data returned

Input Parameter Syntax for Legacy Object models

The following two code samples contain code for the InfoPath 2003 SP1 Managed Object Model (C#) and Jscript (InfoPath 2003 Object Model)

1) C# InfoPath 2003 SP1

In the InfoPath 2003 SP1 Object Model the InputParameters collection is exposed off the XDocument object not off the eventArgs object. Also since this is a new feature the XDocument object needs to be cast to the newer _XDocument3 interface to get access to the InputParameters collection. Hence the first line of code in the sample below.

 [InfoPathEventHandler(EventType = InfoPathEventType.OnLoad)]

 public void FormEvents_OnLoad(DocReturnEvent e)

// Cast XDocument to _XDocument3 to get access to the InputParameters collection
_XDocument3 infopath2007XDocument = (_XDocument3)e.XDocument;

     string bazValue = infopath2007XDocument.InputParameters[“baz”].Value;


string bizValue = infopath2007XDocument.InputParameters[“biz”].Value;


2) JScript

function XDocument::OnLoad(eventObj)
      var bazValue = eventObj.XDocument.InputParameters[“baz”].Value;


Comprehensive documentation and additional code samples for this feature can be found under MSE Help or VSTA Help.

Aditi Desai
Software Design Engineer in Test

Comments (30)

  1. ramkumar1910 says:

    Great introduction!

    it will be very helpful if you could write a bit more on how to use the nput param.

    For exampe:

    how to pass the input param(student id)  to the web service to get the details of one student and display in the form. Thanks

  2. Scott Heim says:

    Hi ramkumar1910,

    Here is some sample code that I tested on the Loading event – note this does not have any error handling though:

    string strCustID = e.InputParameters["CustID"];

               DataSource dsCustomers = this.DataSources["GetSelectedCustomer"];

               XmlNamespaceManager ns = this.NamespaceManager;

               XPathNavigator xnCustomers = dsCustomers.CreateNavigator();

               XPathNavigator xnCustID = xnCustomers.SelectSingleNode("/dfs:myFields/dfs:queryFields/tns:GetSelectedCustomer/tns:CustID", ns);



    In this sample, I had a secondary data connection called GetSelectedCustomer that takes a CustomerID to pull information for just that customer. I then use the InputParameter to set the "queryField" value of my data connection and then execute that connection.

    I hope this helps!


  3. BobC says:

    Is there a way to set a parameter at the content type or form library level?  I have tried adding a parm in the List Content Type Advanced settings like so:


    but wss seems to lose the ability to open the form since .xsn is no longer at the end of the string.

  4. swaven says:


    I have a question regarding connecting two infopaths.

    How can we connect two infopaths through a common column?

    I have an infopath with CustID1 and this infopath contains another file

    attachment(infopath) and I have to popup the second infopath with the same


    I tried the following code in the OnLoad event.



                  string strCustID = e.InputParameters["CustID"];

                  DataSource dsCustomers = this.DataSources["GetCustID"];

                  XmlNamespaceManager ns = this.NamespaceManager;

                  XPathNavigator xnCustomer = dsCustomers.CreateNavigator();

                  XPathNavigator xnCustomer = xnCustomer.SelectSingleNode("/dfs:myFields/dfs:queryFields/tns:Customers/tns:CustomerID");




              catch (exception e)




    but encountered the following error:

    System.Collections.Generic.KeyNotFoundException was unhandled by user code

    Message="The given key was not present in the dictionary."



         at System.ThrowHelper.ThrowKeyNotFoundException()

         at System.Collections.Generic.Dictionary`2.get_Item(TKey key)

         at Microsoft.Office.InfoPath.Internal.ReadOnlyDictionary`2.System.Collections.Generic.IDictionary<K,V>.get_Item(K key)

         at Customer_Checklist.FormCode.FormEvents_Loading(Object sender, LoadingEventArgs e)

         at Microsoft.Office.InfoPath.Internal.FormEventsHost.OnLoad(DocReturnEvent pEvent)

         at Microsoft.Office.Interop.InfoPath.SemiTrust._XDocumentEventSink2_SinkHelper.OnLoad(DocReturnEvent pEvent)

    Is this the process for transferring the value of a field from one infopath to another infopath.  

    Thanks in Advance

  5. zullu says:

    Hi Scott,

    Your sample code was of great help to understand few more concepts in InfoPath 2003.

    Thanks again for this.

    I have another small question.

    Can we create a secondary data connection with a filter criteria set as parameter to receive a value of a sharepoint list column for the current record pointer.

    Thanks for all your help,


  6. zullu says:

    I was able to figure out my stuff through a web service for the second alternative way.

    Thanks to responses from David Dean, Sr. Member Technical Staff, Insource Technology Corp. and Kit Kai’s Blog post at the below url:

    which helped me to resolve my issue quickly.

    Thaks again.


  7. shamrez says:


    Thanks for this informative article. I have a question. If I pass parameters from one InfoPath form to another, I know that is possible but what If I want to send data back to the first InfoPath form. How will I do that? I am using web forms and my InfoPath template is hosted in a forms library in SharePoint. I want to open a new InfoPath form from my xsn template. After doing some processing in the newly opened form I would like to send the processed data back to the original form that is hosted in SharePoint. Can this be done? Plz help!



  8. shamrez says:

    Some more info! I created an aspx page that has a xmlformview control and this page is hosted in SharePoint (main site on port 80). I send some parameters in querystring to this aspx page from an InfoPath form hosted in SharePoint. I do some business processing and now I want to send the data back from this aspx page to the InfoPath form opened from SharePoint. How will we do this? Is it possible at all? Please help!



  9. AD28 says:

    Is there any way we could see the VB version of the InfoPath 2003 SP1 which is displayed in C# above?

    I am very unfamiliar with syntax of both, but need to have this functionality written in VB however.

    I would be so thankful for any help. 🙂

  10. AD28 says:

    I should say VBScript………

  11. CraigSchaeferWU says:

    From the comments above, it appears that


    should work with Infopath 2003.  However when I implemen this I get the following error:

     The form contains XML that cannot be parsed:

     An invalid character was found in text content.

     Line 1, Position 5



    I know the code is working becuase it works fine on Infopath 2007 clients.  Should this work for infopath 2003?

  12. sakons says:


    I use infopath 2007  inside sharepoint 2007 and I would like to pass parameters to the form via the querystring but it doesnot work the way you show it – no data enter the controls

    I am posting the url

    It is a bit different from the your example  but its the url I can get out of the new item in the sharepoint list the form is in it



  13. sukebeta says:

    I am using InfoPath 2003 SP3. I was trying to use JScript to get the input parameter from the URL. My url looks like this:


    Then on the OnLoad event of the form, I was trying to get the value of parameter "view":

    var viewValue = eventObj.XDocument.InputParameters["view"].value;


    I got an error like this

    A runtime error has occured. do you want to debug? the following error has occured:

    ‘XDocument.InputParameters.view’ is null or not an object

    File: script.js

    Line: 58

    anyone know why it didn’t work?

  14. forrestd says:

    As it says in the first paragraph, Input Parameters are a new feature for InfoPath 2007.

  15. dkarantonis says:

    hi to all,

    i am using the e.InputParameter["List"] in order to get the list ID from the url and i get the exception "The given key was not present in the dictionary.". The List exists on the URL (this is a workflow list association form).

    Any ideas?

  16. infopath says:

    Hi dkarantonis,

    In this scenario, the "List" parameter is not an "InputParameter" to the form. If you debug this you will see the InputParameter count is zero. I have been unable to find a way to get this from behind the InfoPath form – so you may want to look at trying to get the URL and parsing it from the ASPX page.


  17. dkarantonis says:

    Hi Scott

    i have commented on your "Submitting to ‘this’ document library" article.

    thanks again

  18. JohnCHill says:


    I understand the parameter piece of this but I cannot figure out how query or filter the data to only show records that match the parameter criteria. Can you help or point me to some other documentation?



  19. I&#39;m currently working on a project that involves the modernization of lotus notes application to

  20. mike11stevens says:

    Has anyone successfully used input parameters in a SharePoint / Forms Server scenario?  Like several other commentors here, I am having trouble getting the url correct/working for my Forms Server forms…any/all help here would be greatly appreciated – thanks!

  21. RRichie says:

    I believe there is a bug in InfoPath 2003 SP3 as with several machines and several forms I get

    The form contains XML that cannot be parsed:

    An invalid character was found in text content.

    Line 1, Position 5



    Same code works in InfoPath 2007. As MainStreamSupport has just ended, I guess there is no hope for a bugfix?! However, my 450k-Employee-Org is still using InfoPath 2003…

  22. wizardntexas says:

    So my question is, if I have data in a dropdown. How can i create a scheme where if in form "A" 6 items are selected from a dropdown box, then form submitted to library. Next user of the form "A", those 6 items are not availible in the drop down list. IE they are checked out? If sharepoint and infopath are these great collaboration tools, why can’t I make them work in a dynamic role, Why must everything be so static?

    Please advise?

  23. Niranjan Julapelly says:

    Hello all ,

    Is there any way to dynamicaly add those input parameters to form template instead of manually adding those query parameters , i have scenerio of 10 subsites and each subsite has 10 form libraries and i published template as content type to top site and iam trying to pass their respective subsite name and form library name as parameters to template url by changing the advanced settings of respective form library. so iam doing this this process 100 times 🙁

  24. hansict says:


    Thanks for this article!

    I have a problem with the URL. Setting the parameters with the Command Line everything is OK, but in URL only the forms opens without data.

    I'm using a webservice.

    I would be so thankful for any help!

  25. Mirdin says:

    Hello. What do you think about adding new feature (in next version):

    Include new Data Connection Type "From Parameters" for data loading from input parameters.

  26. Peter van der Smitte says:

    We have got this to work almost flawlesslessly with InfoPath 2007

    But we bumped into two problems.

    A) The input parameters used are persistent, because the entire comandline is stored in the mso-infopathsolution PI (Processing Instruction) section of the xml instance that is created.

    B) Opening up two instances of a form using input parameters concurrently may cause an error to occur with the following error message:

    [InfoPath cannot open the form because another version of the form template is currently open. Close all forms using the form template and try again.]

    We found that KB Article ID: 957385…/957385 adresses both these issues.

  27. Geert LArsen says:

    Is this viable for SharePoint/InfoPath 2010 ?

  28. karen says:

    Is this for infopath 2007 or 2010?

    I have no programming menu under my tools.

  29. Betty Stolwyk says:

    Any updates for this same question but with InfoPath 2013, SharePoint Designer 2013 in an Office 365 environment?