Displaying your InfoPath Forms in a Web Part

So here I am again with another "did you know". This one is also inspired by Inside Microsoft Office SharePoint  Server 2007.
Did you know that you  can display browser enabled InfoPath forms in a web part?

If you create a form that is published to the SharePoint Form Services in the Central Administration and you have selected that users can open the form in their browsers, you can display the form in a web part. This means that the form page will get a SharePoint look and feel, instead of an InfoPath look and feel.

It is easy to configure and you don't need a single line of code.

The web part that is able to show the form is already created for you by Microsoft and is part of the Microsoft.Office.InfoPath.Server.dll assembly. This assembly is stored in the C:\Program Files\Microsoft Office Servers\12.0\Bin folder.

The first step you have to take to enable the web part to show you InfoPath page is to add a SafeControl entry to the web.config of the web application where you want to use the web part.
The SafeControl entry should look like this:
<SafeControl Assembly="Microsoft.Office.InfoPath.Server, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.Office.InfoPath.Server.Controls" Typename="XmlFormView" Safe="True" />

Now go to your browser and open the Web Part Gallery from the Site Settings page of your SharePoint environment. Click on the New button and you will get a list of available web parts. Look for the entry Microsoft.Office.InfoPath.Server.Controls.XmlFormView and check the checkbox in front of it. Next click the Populate Gallery button at the top of the page. The web part should now be available for use in the site collection.

You can check this by going to a web part page within your site collection and click Edit Page from the site actions menu. In the page click on the Add a Web Part link of a web part section. Now choose the XmlFormView web part that can be found under the Miscellaneous section. An error is generated because you still need to set some properties for the web part. You can simply close the error and go to the properties of the web part to set them.

Go to the  Features section at the bottom of the properties list. Expand the section and decide whether you want to display the header and the footer of the form. Since the form is displayed in the middle of the page you probably don't! If you want users to be able to fill in the form in the web part you want to set the EditingStatus to Editing. In the DataBinding section you find the XsnLocation, the XmlLocation and the possible path to the container where you want to save the form to.

If you are displaying a blank form you want to have the XsnLocation pointing to the location where the .xsn file of you form is published to.
If you are displaying an existing form you can have the XmlLocation point to the location of that form.

If you have filled in these properties correctly your web part should now be displaying you form!