Brendan Tompkins [MVP]

Sponsors

The Lounge

News

Advertisement

Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
A Simple InfoPath Web Viewer Control

Here at the Port, we recently needed to allow different people in the company to quickly publish forms to our public web site. When I was tasked with making this happen, my first thought was to create a simple web-based tool for form creation.  Now, I've done this before, and creating a web-based form designer is no easy task, so  I started thinking of other options.  I could let them use FrontPage to create the forms, and then I could integrate the form into our site.   Honestly, this seemed like it would be more trouble than it would be worth.  Using FrontPage isn't a skill that most power users have.   On top of it, FrontPage doesn't create XHTML, and I wanted to end up with a document that I could parse if I needed to.  On top of all that, I remembered that I really dislike FrontPage...

Then I remembered that everyone here has Microsoft InfoPath installed.  I figure it's only a matter of time before people learn to use it, and in my opinion, it's easier to design a form in InfoPath than FrontPage.  The problem is that putting InfoPath forms on the web isn't so simple.  The end user has to have InfoPath installed in order to fill out an InfoPath form.  Since we wanted to publish the forms to our public site, this wasn't going to be an option. 

So, I came up with a quick solution that solved my problem.  I created a simple InfoPath web viewer that renders the InfoPath form as an HTML form, then takes the results from that form and creates a DataSet.  The resulting DataSet can then be bound to a WebControl, stored in a database or as stored as XML.

The way this all works is simple.  InfoPath has an option to “Extract Form Files.”  This creates, among other things, an XML and XSLT file that can be used to generate the UI of the form. I created a control that transforms this into XHTML, and then does some massaging using a NodeReader and some Regex to create HTML form input elements.

So, here's what an example form looks like in InfoPath:

...and here it is displayed by my InfoPath web viewer control:

You can download the ASP.NET C# project here.

Now there are a couple of big caveats to this control:

  • It doesn't integrate the results back into infopath format.  I'd rather have a DataSet, so that's where the results end up.
  • I only coded Text Areas, Text Boxes, Radio Buttons, and Drop Down Lists. Infopath has a number of other controls, that you can drop on the form.  I didn't need them immediately, so I didn't code support for them.
  • I didn't implement any form validation..

Now, if you peek at the code, you'll see that I used a combination of a NodeReader and REGEX to make this work.  A better solution may be to create a single XSLT file that does this work, but I'm not that good with XSLT syntax, so I didn't go down this route.   Anyhow, try it out!

-Brendan

 


Posted 05-24-2004 7:54 AM by Brendan Tompkins
Filed under:

[Advertisement]

Comments

Lamont wrote re: A Simple InfoPath Web Viewer Control
on 05-24-2004 5:15 AM
Brendan,

Check this out.

http://infoview.uniqueworld.net
Brendan Tompkins wrote re: A Simple InfoPath Web Viewer Control
on 05-24-2004 6:15 AM
Info View Pricing (US $)

Servers Pricing
1
$7,000

2-3
$6,000

4+
$5,000

-B



JosephCooney wrote re: A Simple InfoPath Web Viewer Control
on 05-24-2004 3:34 PM
This is cool. When I first heard about infopath I wondered if it was just "IE under the covers". I mean, the "custom" code that you wrote for it was in jscript/vbscript and it was all xml driven. Recently the update has been released that allows you to write managed custom code etc, so that de-bunks my theory a bit. Authentic from Altova (who make XML spy) is similar to infopath but it has a asp.net server control available as well. I always thought it was a shame that Microsoft did not provide similar for InfoPath.
Alex Irazabal wrote re: A Simple InfoPath Web Viewer Control
on 06-29-2004 7:09 AM
I downloaded the example but could find not way to see if and how it worked! What must you do to activate the WebControl in Infopath? IS there some documentation you can point me to?
Thanks,
Alex
Brendan Tompkins wrote re: A Simple InfoPath Web Viewer Control
on 06-29-2004 7:10 AM
This is an ASP.NET application that will load and view an InfoPath form.
Alex Irazabal wrote re: A Simple InfoPath Web Viewer Control
on 06-29-2004 7:14 AM
Sorry to be so obstuse - but how does it load it? When I try to "run" it wants me to select "an initial web page"?
Noy wrote re: A Simple InfoPath Web Viewer Control
on 07-04-2004 3:02 AM
Hi,
What about repeating section and optional section? is it coded to?
Hans wrote re: A Simple InfoPath Web Viewer Control
on 01-08-2005 2:04 AM
Throw overboard infopath,maybe within 3 years it will be really implemented.
PDF writer does everything better,faster,eaysier,and much mor features !
and everyone has acrobat to fill in and more.
Enrique Ortuño wrote re: A Simple InfoPath Web Viewer Control
on 01-13-2005 11:49 PM
Great work!
mrazek wrote re: A Simple InfoPath Web Viewer Control
on 05-12-2005 7:26 AM
Hi,
I try it use this contol for Infopath form where I use combo with connection to MS SQL database (to view data to combo) but withou success. Can I use this Infopath contol for this example ?

Thanks
Brendan Tompkins wrote Dreading writing your "Blog'n to PDC" entry? Use my PDCContestEntryService and Win a COM+ in .NET Book
on 06-30-2005 6:48 PM
This post is a bunch of things, wrapped up in one.  First and foremost, it’s my Official entry...
Brendan Tompkins wrote Dreading writing your "Blog'n to PDC" entry? Use my PDCContestEntryService and Win a COM+ in .NET Book
on 06-30-2005 6:52 PM
This post is a bunch of things, wrapped up in one.  First and foremost, it’s my Official entry into...
Brendan Tompkins wrote Dreading writing your "Blog'n to PDC" entry? Use my PDCContestEntryService and Win a COM+ in .NET Book
on 06-30-2005 7:00 PM
This post is a bunch of things, wrapped up in one.  First and foremost, it’s my Official entry into...
Brendan Tompkins wrote Dreading writing your "Blog'n to PDC" entry? Use my PDCContestEntryService and Win a COM in .NET Book
on 06-30-2005 7:04 PM
This post is a bunch of things, wrapped up in one.  First and foremost, it’s my Official entry into...
Brendan Tompkins wrote Dreading writing your "Blog'n to PDC" entry? Use my PDCContestEntryService and Win a COM in .NET Book
on 06-30-2005 7:13 PM
This post is a bunch of things, wrapped up in one.  First and foremost, it’s my Official entry into...
Brendan Tompkins wrote Dreading writing your "Blog'n to PDC" entry? Use my PDCContestEntryService and Win a COM in .NET Book
on 06-30-2005 7:17 PM
This post is a bunch of things, wrapped up in one.  First and foremost, it’s my Official entry into...
Brendan Tompkins wrote Refactoring My PDCEntry Service
on 07-05-2005 2:18 PM
Earlier today I was inspired by Jeff Atwood’s blog post on Software Rot:

Coding Horror: The...
Brendan Tompkins wrote Refactoring My PDCEntry Service
on 07-05-2005 2:19 PM
Earlier today I was inspired by Jeff Atwood’s blog post on Software Rot:

Coding Horror: The Broken...
Brendan Tompkins wrote Refactoring My PDCEntry Service
on 07-06-2005 6:55 AM
Earlier today I was inspired by Jeff Atwood’s blog post on Software Rot:

Coding Horror: The Broken...
David wrote re: A Simple InfoPath Web Viewer Control
on 07-11-2005 7:48 AM
InfoJet Service is a Java class library to publish InfoPath Forms to the Web. InfoJet Service can be deployed as Web Services. J2EE and .Net Web application with integration of InfoJet Service support the users to edit InfoPath Forms in Internet Explorer and FireFox.

http://www.infojetsoft.com

thanks
Raphael Londner wrote InfoPath en mode web...
on 07-20-2005 3:09 AM
Raphael Londner wrote InfoPath en mode web...
on 08-04-2005 4:44 AM
Le poste de travail, un gisement de productivit wrote Qu'est-ce qu'un Viewer Infopath ? R
on 09-03-2005 12:47 PM
Jesús wrote re: A Simple InfoPath Web Viewer Control
on 09-08-2005 6:44 PM
This is very cool... thanx...
Le poste de travail, un gisement de productivit wrote Qu'est-ce qu'un Viewer Office Infopath ? R
on 09-16-2005 12:51 PM
U Rule wrote re: A Simple InfoPath Web Viewer Control
on 10-06-2005 9:01 AM
Very good saves us money using InfoView.
Fabio Almeida wrote re: A Simple InfoPath Web Viewer Control
on 10-10-2005 10:20 AM
Hi Brendan,
I'm testing the InfoPathControl to use it in my company. But I'm having problems to submit my InfoPath Form to a SQLServer DataBase when I fill it by IE in a WebApplication. Maybe because I don't have pratice with C#.
Would You pelase help me in doing that ? Is it using DataSet Class ?

Thanx
Fabio - from Brazil
Alessandro's Blogs wrote A Simple InfoPath Web Viewer Control
on 11-05-2005 2:01 AM
Alessandro's Blogs wrote A Simple InfoPath Web Viewer Control
on 11-05-2005 2:04 AM
Le poste de travail, un gisement de productivit wrote Qu'est-ce qu'un Viewer Office Infopath ? R
on 11-15-2005 1:52 AM
azert wrote re: A Simple InfoPath Web Viewer Control
on 06-11-2006 10:50 AM
erer
corey wrote re: A Simple InfoPath Web Viewer Control
on 07-20-2006 4:50 PM
Infopath should just be the form design component for frontpage. The fact that you can't publish to DHTML is ridiculous. Who will use this product, if you actually have to buy another license of Infopath just to fill the stupid form in? What if you wanted to use this for an order form, you make all your customers buy Infopath? That's a great business model... I can't believe MS has sold a single copy of this
Vipul wrote re: A Simple InfoPath Web Viewer Control
on 12-27-2006 3:21 AM

THis control is not confortable with following infopath Control:

Picture

Optional Section

Repeatig Section

Link Picture

Expression Box

If you have solution with this, pls send me

Troubled wrote re: A Simple InfoPath Web Viewer Control
on 02-13-2007 2:28 PM

I have been trying to create a rich text box that has text wrapping and does not expand the textbox. The textbox has enough space for 3 lines of text, but when you press enter the textbox expands and throws off the pagination of the whole form. I am using InfoPath with InfoJet. Do you know of a solution that could help?

I've tried show scrollbars when necessary- doesn't work.

David wrote re: A Simple InfoPath Web Viewer Control
on 06-25-2007 12:13 PM

I am new at ASP .NET and I downloaded this project to test it ou.  I was able to succesfully transforrm the xml schema/files to a ASP .NEt application.  I then saved the file as HTMl file to post on the website.  if anyone cares to know, here are the steps to follow:

1. Open Visual Studio, click open file, find the C# sharp project from this website and select InfoPathControl folder.  Click open.

2.  Look in InfoPathDoc file in the Visual Studio browser. This folder contains the xml schema or files to be transformed and viewed as ASP . NET project.  Of course this is where you would place the files you would like convert.

3.  Once the files are loaded as explained in 2, then proceed to run the project (F5, or green arrow).  The transformation should take a short time to complete, in my test I only tried a couple of pages length form.

4.  Once the form is displayed in IE browser (i did not test in different browser), then save the result as an html, and place it where it will be exposed to users.

As already mentioned by Brendan the author there are some important drawbacks.  In the forms i tested the repeating rows tag is simply displayed as text tag without functionality, some pictures did not display at all, and some drop down menues did not get populated.

Goind forward i have heard that InfoPath 2007 wil have this feature/ability of creating forms ONCE for the web browsers while creating the InfoPath version of it.  Development shoul be shorter as well as maintenance.

Dani wrote re: A Simple InfoPath Web Viewer Control
on 06-26-2007 10:04 AM

Can someone point me in the right direction on how to submit the information collected in html format to the InfoPath server?  I have the collected data in html format but i need to connect and submit the data, how do i do that?

mahesh wrote re: A Simple InfoPath Web Viewer Control
on 04-08-2008 1:29 AM

User will enter number in textbox that need to displayed in Fax formate Let us take i enter 060009999 that need to be displayed as 06-000-9999

Krishna wrote re: A Simple InfoPath Web Viewer Control
on 02-16-2009 3:55 PM

I have a Windows application and I am looking something similar to your solution to display Infopath forms irrespective of Clients maching having Infopath installed or not.

Do you know if there is anything that would solve my problem

paco wrote re: A Simple InfoPath Web Viewer Control
on 04-20-2009 7:59 AM

Hi,

Just want to know where can I find a list af infopath live web examples?... why is so hard to find live examples for web browsers?

Thanks

Add a Comment

(required)  
(optional)
(required)  
Remember Me?