Sunday, August 20, 2006

Publishing Infopath form on Sharepoint Pages

The msdn document at

shows us how we can host our infopath form in a custom aspx page or a Windows Application.

What I would show here is how you can display your infopath form on the sharepoint page.

The hosting of infopath form on a sharepoint page can be done with either two ways :

  • Using Sharepoint Designer and dropping a XMLFormView Control
  • Creating a Webpart for hosting the infopath form

We will be using the second method since it is more intuitive. To develop a simple webpart for

Hosting infopath form, we will create a simple Class Library in Visual 2005 and add a reference

to Microsoft.Sharepoint

The main code we will be writing is in the CreateChildControls section.

protected override void CreateChildControls()





control = new Microsoft.Office.InfoPath.Server.Controls.XmlFormView();

control.XsnLocation = text;



catch (Exception e)


EventLog.WriteEntry("Office", e.Message + e.Source + e.StackTrace, EventLogEntryType.Error);



In the above code, we have created a XMLFormView control programmatically. This control is in

Microsoft.Office.Infopath.Server.Controls namespace and this dll is located in Office Server directory

In Program Files directory.

In addition to it, we can use a property which can take the location of xsn file on sharepoint site to host. We will create

A property called xsn






Description("XSN Location")]

public string Xsn




return xsn;




xsn = value;



And then we can change the CreateChild controls code to take the xsn file location from the

Property like

control.XsnLocation = Xsn;

I can mail the source code to anyone if interested.

Mail me your suggestions. J

kick it on