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!

Print | posted @ Tuesday, March 10, 2009 9:18 AM

Comments on this entry:

Gravatar # re: Displaying your InfoPath Forms in a Web Part
by Ian Morrish at 3/12/2009 7:37 AM

A full list of the web part properties can be fond here
msdn.microsoft.com/.../...formview_properties.aspx

After adding the web part to a page you may find that you can't edit its properties. In that case you can edit the web part xml file by hand. Example www.wssdemo.com/.../...t-xmlformview-web-part.aspx
  
Gravatar # re: Displaying your InfoPath Forms in a Web Part
by MAW at 3/14/2009 12:55 AM

Thanks, I tried this out, checked the dll was present, then STOPPED my sharepoint site, edited its web.config, inserted the whole <SafeControl Assembly line and restarted. The site would not load - Error. The IIS log file in C:\WINDOWS\system32\LogFiles shows error 401 loading Infopath (compatible;+MSIE+7.0;+Windows+NT+5.2;+.NET+CLR+1.1.4322;+.NET+CLR+2.0.50727;+InfoPath.2;+.NET+CLR+3.0.04506.30) 401 2 2148074254

I checked and changed the end bit Safe="True"> to Safe="True"/> but still nothing. So I commented out the line in my web-config, restarted and my MOSS site works again.
Why doesn't the safecontrol work?
  
Gravatar # re: Displaying your InfoPath Forms in a Web Part
by Mirjam at 6/29/2009 8:52 AM

Hi Don,

You are right, I adjusted the post.

Thank you!
Mirjam
  
Gravatar # re: Displaying your InfoPath Forms in a Web Part
by Dan at 11/18/2009 7:23 PM

I am having the same issue reported by MAW. Once I add the safecontrol entry to the web.config, the site won't post -

Server Error in '/' Application.
--------------------------------------------------------------------------------

Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.

Parser Error Message: This page has encountered a critical error. Contact your system administrator if this problem persists.

Source Error:


Line 1: <%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> <%@ Reference VirtualPath="~TemplatePageUrl" %> <%@ Reference VirtualPath="~masterurl/custom.master" %>
Line 2: <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head>
Line 3: <!--[if gte mso 9]><xml>


Source File: /Pages/default.aspx Line: 1


--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3603; ASP.NET Version:2.0.50727.3082

Any Ideas?
  
Gravatar # re: Displaying your InfoPath Forms in a Web Part
by Dan at 11/18/2009 8:39 PM

never mind my previous message - eventually I found a typo in my safe control entry (Typename instead of TypeName). Another question though, when the infopath form loads normally (i.e., not in the web part) I do some intializing in the form load event. this doesn't seem to happen when the form is in a web part. any ideas on how to detect when the form is "loaded" as part of a web part?
  
Gravatar # re: Displaying your InfoPath Forms in a Web Part
by sharda at 5/4/2010 5:24 AM

I have created below webapp:
sharepoint-3677
sharepoint-80
Cneteral WebApp

sharepoint-3677 is working fine.

but sharepoint-80 has following error when i browese in Explorer .

Please suggest me what can i do for this.
before 10 days it was working fine for me .


Parser Error Message: This page has encountered a critical error. Contact your system administrator if this problem persists.

Source Error:


Line 1: <%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %> <%@ Reference VirtualPath="~TemplatePageUrl" %> <%@ Reference VirtualPath="~masterurl/custom.master" %>
Line 2: <html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head>
Line 3: <!--[if gte mso 9]><xml>


  

Your comment:

Title:
Name:
Email:
Website:
 
Italic Underline Blockquote Hyperlink
 
 
Please add 7 and 3 and type the answer here: