Infopath form server - passing url parameter to a infopath form   

Tags: SharePoint 2007, InfoPath
Technorati Tags: ,

 

I wanted to load a new infopath form into a Xmlformview webpart in Sharepoint, but at the same time pass a url queryparameter to the infopath form.
At first you might think that this can't be done without code behind on the infopath form but I found an easy way to do this based on an article (Steven Van De Craen) of a collegue of mine.
The methods are quit simple

  1. Make sure u get a url parameter in the publishing page by clicking a link (ex http://moss/pages/createdoc.aspx?parameter=23
  2. Create a new custom SharePoint webpart that extends the Microsoft.Office.InfoPath.Server.Controls.XmlFormView class.
  3. Add an eventhandler in the onInit of the webpart for this.initialise
  4. In the handler add code to change the XML nodes in the infopath doc (pass parameter to a hidden field or something).

public class XmlFormViewExtender : Microsoft.Office.InfoPath.Server.Controls.XmlFormView
{
private bool _error = false;
private string _xpath = null;
private string _param = null;
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[System.ComponentModel.Category("My Property Group")]
[WebDisplayName("parameter")]
[WebDescription("parameter Property")]
public string Param
{
get
{
if (_param == null)
{_param = "par";
}
return _param;
}
set { _param = value; }
}
[Personalizable(PersonalizationScope.Shared)]
[WebBrowsable(true)]
[System.ComponentModel.Category("My Property Group")]
[WebDisplayName("XPath")]
[WebDescription("XPath Property")]
public string XPath
{get
{
if (_xpath == null)
{
_xpath = "/my:form/my:param";
}
return _xpath;
}
set { _xpath = value; }
}
protected override void OnInit(EventArgs e)
{
this.Initialize += new EventHandler(XmlFormViewExtender_Initialize);
base.OnInit(e);
}
protected void XmlFormViewExtender_Initialize(object sender, Microsoft.Office.InfoPath.Server.Controls.InitializeEventArgs e)
{
if (XmlForm != null)
{
string value = this.Page.Request.QueryString[Param];
XPathNavigator _xNavMain = this.XmlForm.MainDataSource.CreateNavigator();
XPathNavigator result = _xNavMain.SelectSingleNode(XPath, this.XmlForm.NamespaceManager);
result.SetValue(value);
}
}
I've also created 2 properties (Param, XPath) for the webpart that hold the name of the parameter it should get (querystring) and the Xpath where to place the value of this param.
So the result of this webpart is that the value of the url parameter par will be filled into the XML of the infopath form in "/my:form/my:param" and will show this data when rendering the form.

 

Hope this helps someone out!

 
Posted by  Van Rousselt Tom  on  4/21/2010
0  Comments  |  Trackback Url  | 0  Links to this post | Bookmark this post with:        
 

Links to this post

Comments

Name:
URL:
Email:
Comments: