How to create an XMLFormView control in custom aspx page within SharePoint?

Adding “XmlFormView” control to a custom aspx page that provisioned within SharePoint throws an exception “Session state cannot be enabled here.”

XmlFormView control requires session state to be enabled.


To enable the session, open the web application’s web.config file,

1. Under <httpmodules> enable the session module
<add name="Session" type="System.Web.SessionState.SessionStateModule"/>
2. Set the <page> tag attribute enableSessionState="true"
3. Add a Safe control entry for the XmlFormView control
<SafeControl Assembly="Microsoft.Office.InfoPath.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.Office.InfoPath.Server.Controls" TypeName="*" Safe="True" />

4. In aspx page the control tag looks like :- <cc1:XmlFormView ID="XmlFormView1" XsnLocation="~sitecollection/FormServerTemplates/Userfeedback.xsn" runat="server" Height="250px" Width="100%"/>

Note: If you are gonna write some code within your custom aspx page then you need to write add the node <PageParserPath> in your web.config file of your web application

 

To allow the inline script

<PageParserPaths>
<PageParserPath VirtualPath="/_catalogs/masterpage/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />
</PageParserPaths>