Passing query string to a Infopath 2007 form
Support of infopath 2007 browser rendering has opened a whole lot of options for web forms. Now instead of creating a form in ASPX , one can create an infopath form and take advantage of various submitting options like submitting to web service, database etc.
One feature which I find hard to get is passing parameters to infopath form so that it can dynamically present the data to user. For Ex you can pass a customer id to the infopath form which updates the database based on that customer ID.
Normally rendering the infopath form using document library prevents us to pass our own parameters throught the URL since the URL is automatically generated by the Forms Server.
The trick is to use XMLFormView control as described in this link
http://msdn2.microsoft.com/en-us/ms778201.aspx
Observe the code in OnInitialize event, here you can grap the parameter in the query string and send it to your infopath form to a text box. That text box can be set to hidden if possible.
Support of infopath 2007 browser rendering has opened a whole lot of options for web forms. Now instead of creating a form in ASPX , one can create an infopath form and take advantage of various submitting options like submitting to web service, database etc.
One feature which I find hard to get is passing parameters to infopath form so that it can dynamically present the data to user. For Ex you can pass a customer id to the infopath form which updates the database based on that customer ID.
Normally rendering the infopath form using document library prevents us to pass our own parameters throught the URL since the URL is automatically generated by the Forms Server.
The trick is to use XMLFormView control as described in this link
http://msdn2.microsoft.com/en-us/ms778201.aspx
Observe the code in OnInitialize event, here you can grap the parameter in the query string and send it to your infopath form to a text box. That text box can be set to hidden if possible.
protected void _xmlFormView1_OnInitialize(object sender, EventArgs e)
{
XPathNavigator xNavMain = XmlFormView1.XmlForm.MainDataSource.CreateNavigator();
XmlNamespaceManager xNameSpace = new XmlNamespaceManager(new NameTable());
xNameSpace.AddNamespace("my", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-04-20T16:26:21");
XPathNavigator fTextBox1 = xNavMain.SelectSingleNode("my:myFields/my:field2", xNameSpace);
fTextBox1.SetValue(Request.QueryString["CustomerID"]);
}
This way you can pass the dynamic parameters to the infopath form rendered in the browser.
Note that the namespace specified here must be exactly same as that specified in your form.
To find out your namespace, rename the .xsn file to .cab and open the template.xml file.
Happy Working :)
2 comments:
Hi there,
I have an infopath form in a in an XMLFormview control as described in the MS778201 link, and I have the web page in a page viewer control on the sharepoint site. How do I pass the parameters from the sharepoint web page to the page viewer control, so that I can use them in the infopath form?
Thanks,
Garth
Hello Garth
Did you able to resolve this issue? If yes let me know or send me sample code on ashishkanoongo@hotmail.com
Ashish
Post a Comment