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


Siva Phim said...

I am new to SharePoint development.

I read about your blog with regards to Outlook.

Can you advise how to code a simple
webpart which assigns the current user and servername to this webpart on load and display it on page.


Sorry for the post here, could not find a contact.

Dan wrote:
> I am trying to setup Sharepoint and it is necessary to display a
> user's calendar/tasks etc. I think this should be easy given we are
> supplied with the "My Taks", "My Calendar" Web parts etc.
> However it is asking for two things.
> 1) Mail Server Address
> 2)Mailbox
> I am ok with the first item as its just http://server_name/exchange.
> However the second item - Mailbox doesn't make much sense. This
> should be dynamic and change depending on which user is currently
> logged in!
> I have tried to see if there is anything i can do in the .aspx page,
> but all i see is:
> MailboxName
> xmlns="urn:schemas-microsoft-com:owapart">dalmanMailboxName
> Can I get this to be dynamic and change depending on the user logged
> in???
> Thanks,
> Dan

Hi Dan

If you are using Exchange 2007, then you are in luck. Because these webparts
behave exactly as you want with exchange 2007.
However with older versions of Exchange, what can you do is, code a simlple
webpart which assigns the current user and servername to this webpart on
and display it on page.

Hope this helps

Madhur Ahuja

Madhur said...

hi Siva...
I have a aleady built such webpart. send me ur email and ill send you one. i have enabled my email visibility on this profile...

Anonymous said...

How to download it????

Madhur said...

i was not able to upload the webpart.
I can mail the source code.

Anonymous said...

When the My Calendar and My Inbox webparts are used on the My Site, I can access the server and user account, but the web part is displaying the full OWA user interface (instead of just the calendar or just the inbox). Any ideas on how to get these to function correctly?

Madhur said...

tell me the values you are entering
for the webpart configuration.

Anonymous said...

For the My Inbox webpart:

Mail Server Address:


Two Line

All other parameters are defaults.

Madhur said...

Does ur Outlook web access opens normally?

Anonymous said...

If I browse to the OWA site (with IE), it prompts me to login and then displays the normal OWA screen. When I use this same OWA address in the My ... webparts, it browses to the same login window. In other words, the My... webpart should bypass the normal OWA screens and bring up just my calendar, or my inbox. Right?

Bob C said...

Source code?

Anonymous said...

Dear jeff, am having the same problem regarding entering the owa credentials whenever i view mysite in the my calendar and inbox webparts, did u solve this issue?
Amer Anabtawi

Unknown said...

i don't see the XMLFormView Control in the SharePoint Designer - how do I bring it in there?

Anonymous said...

see this

It is present in this assembly

Akhila said...

Hi All,

Im working on creating a workflow initiation form for sharepoint . I
have form server 2007 installed and running with which I am browsing
the infopath forms .
my workflow.xml looks like this

<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="">
<Workflow Id="F487360C-097F-42A2-B417-95F180C23B70"
Name="OR Workflow"
Description="Orange WFs "
CodeBesideAssembly="OrangeWfs,Version=, Culture=neutral,
InstantiationUrl ="_layouts/InitWf.aspx">

and feature.xml looks like this

<?xml version="1.0" encoding="utf-8"?>

<Feature Id="C31B9019-27FE-4BF3-8F44-FF3B189A401A"
Title="Orange Workflows"
Description="Click to ACtivate OS WFs"

<ElementManifest Location="workflow.xml" />
<Property Key="GloballyAvailable" Value="true" />
</Feature >

for the workflow initaition I have created a InitWf.aspx that has a
webpart called xmlformview which hosts the infopath form ( some .xsn
form that has some input fields) . I have also created a class file
of this infopath from using the xsd.exe tool .

my workflow1.cs file looks like this

private void onWorkflowActivated1_Invoked(object sender,
ExternalDataEventArgs e)
workflowId = workflowProperties.WorkflowId;

XmlSerializer serializer = new
if (workflowProperties.InitiationData != null)
XmlTextReader reader = new XmlTextReader(new

myFields initform =

toname =;
fromemail = initform.from;
subject = "Test";

where myFields is the name of the class that was created from the
xsd.exe tool.

I have installed the feature and activated it for a site
colllection . Wen I activate the workflow by checking the box labelled
"Start Workflow when new Item is added " and Associate that to a
particular workflow , the workflow getts actuvated and the Page_Load
of workflow1.cs fires but the InitWf.aspx that I had created did not
even load . What could be the reason for this . At the same time when
I manually trigger the workflow the InitWf.aspx opens up and the
later on the forms gets closed the data I entered is not present in
workflow.InitiationData . It is alawys null for me

Could anyone help me in this regard . Banging my head for a long time

Akhila :)

Anonymous said...

Hi there. I am just about to email you directly Madhur regarding the webpart code to automatically add in the username for the My Inbox webpart for Sharepoint 2007. I have spent the last 3 days more or less trying everything I know to edit the existing webpart to make it do this (as it should do really by default!). I would be so greatful if you would send it to me, as I think this will be such a helpful aspect to the new Sharepoint Intranet that I am building! Many Thanks

Graham Reed, St Swithuns School, UK

Anonymous said...

Have you ever considered hosting your applications on fresh servers with fast connection speeds?

mention and receive an extra 10% off or a free month

cheap dedicated servers and colocation

Anonymous said...

Hey guys I offer a free one month trial to check out our virtual servers. Just mention and your in!

888-603-6333 x89

Virtual Servers Hosted

Exchange Hosting

Dedicated Server Hosting

Anonymous said...

OWItTR Hello! Great blog you have! My greetings!

Anonymous said...

UQbrb5 Your blog is great. Articles is interesting!

Anonymous said...

namNCh Wonderful blog.

Anonymous said...

ZrYReu Thanks to author.

Anonymous said...

Hello all!

Anonymous said...

Hello all!

Anonymous said...

actually, that's brilliant. Thank you. I'm going to pass that on to a couple of people.

Zacker said...

Can I get the source code for this article? Please mail me at .