webpart

I recently needed to take a simple InfoPath form and surface that through a ‘themed’ SharePoint page. It’s possible to load the form in a browser without needing a specific page, but this effectively eliminates your master page from the equation.

Nick Grattan wrote an excellent paper on using the XmlFormView control to contain InfoPath forms on SharePoint webpart pages.

This is all great until you then need to send in input parameters to the form. I looked around for quite a while before I found the (rather obvious) Initialize event allows you to set the Input parameters of the form. All other methods of loading the form (InfoPath client, FormServer.aspx) use a querystring-style format.

The following code should do the trick in the case where you’re passing information from a current ‘list item’ to the form:

I discovered that in order to write code in a WebPart page (using SharePoint Designer)
you’ll need to add a PageParserPath to the web.config as follows – otherwise you’ll get an error saying something like ‘code not allowed in this page’. I’ve got a folder called ‘WebPages’ that houses the page. The standard web.config already has the PageParserPaths element:

NOTE: If you’re showing/hiding the form based on a flag/checkbox etc in the page (I’m doing this), then make sure you wrap the XmlFormView in a container Panel/div that you show/hide server-side, rather than showing/hiding the XmlFormView itself. For some reason this doesn’t seem to work properly (at least in FireFox).