Publishing Infopath form on Sharepoint Pages
The msdn document at
http://msdn2.microsoft.com/en-us/ms406041.aspx
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()
{
base.CreateChildControls();
try
{
control = new Microsoft.Office.InfoPath.Server.Controls.XmlFormView();
control.XsnLocation = text;
this.Controls.Add(control);
}
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
[Browsable(true),
Category("Miscellaneous"),
DefaultValue(defaultText),
WebPartStorage(Storage.Personal),
FriendlyName("XsnLocation"),
Description("XSN Location")]
public string Xsn
{
get
{
return xsn;
}
set
{
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