Blog Stats
  • Posts - 79
  • Articles - 1
  • Comments - 30
  • Trackbacks - 191

 

Serve InfoPath Documents Dynamically

I created a little experiment to serve InfoPath documents dynamically from ASP.NET. Once opened, I wanted the form to already be populated with values from a database rather then having two views (Query and Data Entry). Then, the user could make whatever changes necessary and post back to a web service. The user could also save the document for offline editing and submit to the web service when getting back online later.

I ran into a few snags while trying to get this to work and thought I'd throw up here to show how I got around them and see if there are any other solutions floating around.

An InfoPath XML document is marked with a processing instruction (PI) just like other Office 2003 XML documents. This PI (mso-application) tells the OS which application to launch in order to edit that XML document. The InfoPath document also has a PI (mso-infoPathSolution) that ties the XML document to a form that is capable of editing the file. Here's an example of the two PIs:

<?mso-infoPathSolution solutionVersion="1.0.0.1" productVersion="11.0.5531" PIVersion="1.0.0.0" href="http://localhost/Forms/CustomerForm.xsn" language="en-us" ?>
<?mso-application progid="InfoPath.Document"?>

The href tag in the mso-infoPathSolution PI points to the location of the InfoPath form that can edit this XML document.

My first attempt was to use an ASPX page that had the ContentType attribute of the @Page directory set to text/xml. I then included the PIs in at the beginning of the file and returned an XML structure that replicated the structure of my sample XML files from my InfoPath form.

The result was that Internet Explorer would only render the XML. It would not launch the InfoPath application even the PIs were present. Static XML documentes served from the web server worked fine, but my dynamic result would not. I traced this down to a problem with ASP.NET and Internet Explorer. By default, ASP.NET adds a charset parameter to the Content-Type HTTP header. It appears as “text/xml; charset=utf-8“. Due to what I guess is a bug in IE, the charset parameter causes IE to not recognize the PIs at the beginning of the file.

No problem, I turned off the charset parameter:

Response.Charset = "";

After turning off the charset parameter, InfoPath would launch when Internet Explorer received the XML document. However, it seems that InfoPath would go back out and rerequest the page using another method such as FrontPage server extensions. InfoPath would read try to read and use the actual ASPX file.

I guess there are a few ways this could be fixed. One option would be to turn off whatever method InfoPath was using to request the source ASPX file. Another option, and the one I used, was to create a quick HttpHandler that mapped to the .XML extension. The HttpHandler would rewrite the request using the .ASPX extension and call context.Server.Execute(newFileName). This way I could still use ASPX to declaratively describe the XML structure and use databinding to fill in the values.

The actual file with the XML extension does not exist, so InfoPath now uses the document I returned dynamically. It was a bit of a journey, but now I can dynamically create the InfoPath document and link it to a form definition. The user can edit the values in the form and submit it back to the web service.

To integrate it with an over all solution, the user browses a web page that allows searching for records. Once a record is located, the user can view the details, still in the web browser. On the details page, they can click on an URL that will launch InfoPath so they can edit the record using the rich UI features of the InfoPath smart client.


Feedback

# re: Serve InfoPath Documents Dynamically

Gravatar I have a similar application, but server-side is Java. The correct mime-type is "application/ms-infopath.xml", which is put into the registry by the InfoPath/Office install.

Due to an encoding problem I found recently, I also have to set the charset to windows-1252.
2/24/2004 12:22 PM | Perry Faulkner

# re: Serve InfoPath Documents Dynamically

Gravatar Would appreciate if u can mail the sample in which InfoPath was launched when Internet Explorer received the XML document to an email id poonam.thawani@tcs.com
priyaspoonam@yahoo.co.in

Thanks
poonam

4/19/2004 1:50 AM | Poonam Thawani

# re: Serve InfoPath Documents Dynamically

Gravatar Is there another way to launch infopath from IE and pass it a key to lookup with its built in dataconnections? Instead of having to do dynamic xml, which is a cool solution btw. 4/30/2004 10:39 AM | Charlie

# re: Serve InfoPath Documents Dynamically

Gravatar Another option is to just use the http handler to return the infopath xml. It has to have a new file extension to bypass the aspx processing. I found this link to be helpfull in getting up to speed on http handlers. http://www.15seconds.com/issue/020417.htm

Mike 5/2/2004 7:50 PM | Mike

# Getting problem, while accessing the infopath xml file

Gravatar Hi All,

I created an infopath template, using this template, i generated an xml file. Now i want to pull the data from xml file into my VB.Net application. When i use XmlDocument object's Load method to load the xml file, i get this error message as following:- "Object reference not set to an instance of an object. The Xpath is fine over here.

Please help me in fixing the problem.

Details: The default name space which i using in Infopath Scripting
XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2004-06-09T12:15:01"');

and my dot net is accessing like this way...
Choice = xFile.SelectSingleNode("/my:PBPTool/my:Choice").InnerText

Regards,
Rajashekar 6/16/2004 2:06 AM | Rajashekar

# re: Serve InfoPath Documents Dynamically

Gravatar Would be of great help if u can mail the sample in which InfoPath was launched when Internet Explorer received the XML document to an email id
mahan@ctd.hcltech.com
mahanatti@gmail.com

Thanks,
Mahalax. 9/22/2004 5:09 AM | Mahalax

# re: Serve InfoPath Documents Dynamically

Gravatar I'm currently workig on a project where we use InfoPath. The problem i can't get around is the File download dialog that always pops up when downloading an xsn-file.
The checkbox is always disabled, File Types settings won't act.
Any ideas? 11/30/2004 5:01 AM | peter.dercsar@kirowski.com

# re: Serve InfoPath Documents Dynamically

Gravatar Hello, any chance of getting the code you implemented? I would LOVE to do this for a current project. Many thanks. 12/21/2004 12:39 PM | steven.hicks@ngb.army.mil

# re: Serve InfoPath Documents Dynamically

Gravatar Hi, Did anybody get the source code? Is there a website which has this code snippet published? 12/29/2004 4:16 AM | Jo

# re: Serve InfoPath Documents Dynamically

Gravatar Would it be possible for you to email me your code of how you implemented this with InfoPath??

My email is michaelreyeros@hotmail.com 2/14/2005 2:18 PM | Michael Reyeros

# re: Serve InfoPath Documents Dynamically

Gravatar I am not able to creat the infopath form programeticaly what is the best way to create form through coding can some one give a simple wxample like creating text box on the microsoft infopath
samit.pathak@patni.com 4/14/2005 6:06 AM | Samit Pathak

# re: Serve InfoPath Documents Dynamically

Gravatar I've read this post numerous times hoping for some insight into getting past this problem. I finally discovered the solution is too brain-dead simple. Add a query string to the URL for the ASPX page. When IE sees the query string, it bypasses the FrontPAge retrieval of the ASPX source code and send the response from the ASPX page to InfoPath.

At least it worked for me... 5/24/2005 11:28 AM | Greg

# re: Serve InfoPath Documents Dynamically

Gravatar Would it be possible for you to email me your code of how you implemented this with InfoPath??

My email is rrsgem@yahoo.com

Thanks,
Rajesh 8/1/2005 12:12 PM | Rajesh Raman

# re: Serve InfoPath Documents Dynamically

Gravatar I appreciate very much if I could have a copy of your experiment to learn.

Thanks

Boi 9/27/2005 12:11 PM | Boi Bom

# re: Serve InfoPath Documents Dynamically

Gravatar I appreciate very much if I could have a copy of your experiment to learn.

My email is boibom@hotmail.com.

Thanks

Boi 9/27/2005 12:12 PM | Boi Bom

# re: Serve InfoPath Documents Dynamically

Gravatar CODE CODE WHERE IS THE CODE 10/6/2005 5:04 AM | CODE

# re: Serve InfoPath Documents Dynamically

Gravatar Please write the code 10/28/2005 4:48 AM | Please write the code

# re: Serve InfoPath Documents Dynamically

Gravatar Would appreciate if u can mail the sample in which InfoPath was launched when Internet Explorer received the XML document to an email id ravi_mgl@yahoo.com 11/13/2005 8:46 PM | Ravi Kumar

# re: Serve InfoPath Documents Dynamically

Gravatar Thanks. This technique should be discussed as one of the basic ways to work with an xml document...

Now I have to come up with a process to save to a new xml doc based on changes made... 1/17/2006 3:07 PM | Bob Chauvin

# re: Serve InfoPath Documents Dynamically

Gravatar Code:

geekswithblogs.net/imilovanovic/archive/2006/01/17/66175.aspx

bye
Igor 1/20/2006 12:11 PM | Igor Milovanovic

# re: Serve InfoPath Documents Dynamically

Gravatar I am doing similar work but using a Servlet to stream the XML doc and the Template files dynamically.

Infopath is launched correctly from IE with the right XML doc and Template file. But I keep getting the message "
This form cannot be filled out either because you do not have adequate permissions, another user has the form opened or the the form is open in another program.
Do you want to open a read-only version of this form?"

I know that it is not 1 or 2 that is causing it. I can accept to open the form in read-only but can still submit data from the form after that.

Any ideas on what I need to do to suppress the message?
5/24/2006 8:54 PM | sunflower

# re: Serve InfoPath Documents Dynamically

Gravatar Could you please mail the code to pass query strings to the Infopath document 5/9/2007 6:32 AM | Jyothi

# re: Serve InfoPath Documents Dynamically

Gravatar Here is the answer:

Response.Clear()
Response.AppendHeader("Content-Disposition", "attachment;filename=Doody.xml")
Response.ContentType = "application/ms-infopath.xml"
Response.Write(xml)
Response.Flush()
Response.End()

variable XML = your string of the XML Infopath document
*Doody.xml can be renamed if needed 12/4/2007 3:05 PM | Stevo

# re: Serve InfoPath Documents Dynamically

Gravatar Hi

Could you please send me your whole code at email id
gholap.rohidas@gmail.com 7/16/2008 12:19 AM | Rohit

# re: Serve InfoPath Documents Dynamically

Gravatar hi

can you send me the code for launching the infopath from aspx with the values coming dynamically from a web service..

that will be helpful.
9/8/2008 3:00 PM | Pavan

Post a comment





 

Please add 5 and 3 and type the answer here:

 

 

Copyright © Drew Robbins