How do I: Serve InfoPath XML documents dynamically from ASP.NET

The requirement:

I recently received a technical requirement to dynamically serve InfoPath 2007 XML documents from an ASP.NET page. In order to meet this requirement It was useful to understand what actually makes up an InfoPath XML document.

What is an InfoPath Document?

InfoPath XML documents are XML documents with additional XML directives (called Processing Instructions.) These directives can be located by inspecting you InfoPath XML document in a XML editor of your choice.

What are processing instructions?

Processing instructions (PIs) allow XML documents to pass additional information to the applications that consume them. They are not part of the documents data but instead are passed through to the application. Like comments, they are not textually part of the XML document. All processing instructions, begin with <? and end with ?>. PIs must begin with an identifier called a target, which follows rules similar to those for element (XML element: An XML structure that consists of a start tag, an end tag, and the information between the tags.

More info:

What do InfoPath processing instructions contain?

InfoPath processing instructions most important piece of information is the reference to the InfoPath template (XSN) from which the InfoPath XML Document is based.

The solution:

Initially there was some time wasted trying to achieve this by opening the document in a browser without Microsoft Office SharePoint Server 2007 or Microsoft Office Forms Server 2007 but we reached a dead end pretty quickly (more information can be found here.)

This ended up being quite a simple solution once we adjusted our requirements.

Here is the code I ended up using:

XmlDocument MyInfoPathData = new XmlDataDocument();
MyInfoPathData.LoadXml(<!-- Your XML data string here -->);

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

The result:

I was able to successfully stream an InfoPath XML document and open it within an InfoPath 2007 client for editing.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: