The XmlFormView control plays the central role in rendering the display to a user in an HTML compatible format. When not using the Forms Service XmlFormControl within a WebPart, it becomes exceptionally difficult to develop a custom solution to render out the InfoPath form. It could be theorized that one could load the InfoPath XML document by calling a StreamReader on the XML contents, go through all the XML contents, use LoadXml to load the streamed contents, apply the relevant style by looping through the nodes, and other methods. However it is much easier to do it with the Forms Services native XmlFormView control by simply calling it out, and a lot of the methods that would have to be custom written otherwise are handled by the control.
The XmlFormView control can also be consumed from within a SharePoint WebPart or a SharePoint WebPart Page because the required page references are already stored within the SharePoint 12 hive.
WebPartPage XmlFormView Control Registration and Placement
There are very few requirements to get the control to display on a WebPart page within SharePoint. Namely, making the references to the appropriate assemblies to consume the control and then declaratively calling the XmlFormView control. Therefore, it is possible to open a WebPart page using SharePoint Designer. Call the XmlFormView control on the page, and set the relevant properties to point to the .XSN file location.
<%@ Register Tagprefix=”InfoPath”
Namespace=”Microsoft.Office.InfoPath.Server.Controls” Assembly=”Microsoft.Office.InfoPath.Server, Version=184.108.40.206, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>
For some environments, a more modular approach is required, and therefore the XmlFormView should be packaged within a SharePoint WebPart to display relevant InfoPath forms. In order to consume the XmlFormView control within a WebPart, the task is pretty straightforward. Make a reference to the Microsoft.Office.InfoPath.Server assembly and declare a field to hold the control.
private XmlFormView proSP2007Form;
Like the rendering of all child controls that exist in .NET, we simply have to override the CreateChildControls() method and then call out the XmlFormView Control.
protected override void CreateChildControls()
proSP2007Form = new XmlFormView();
proSP2007Form.XsnLocation = “proSharePoint2007XSNlocation”;
Then following in the RenderWebPart method, override the RenderWebPart method and output the XmlFormView control.
protected override void RenderWebPart(HtmlTextWriter output)
By filling in the XSNLocation property, the XSN you want displayed is rendered through a WebPart. If you want to extend the WebPart, use a WebPart property to make the XSN location property adjustable by users through the WebPart ToolPane.