开发者

Extracting XML from XMLFormView

Is there a way to get the XML presented in a XMLFormView? I'm trying to create a custom web part with a "Save as PDF" button for an InfoPath form. The idea is to combine the XML with the form's XSL and make the resulting HTML into P开发者_高级运维DF which is presented to the user as a popup.

Because it is to be presented as a popup, using Workflows is not an option.


http://msdn.microsoft.com/en-us/library/microsoft.office.infopath.server.controls.xmlformview.xmllocation.aspx

This property will give you the Url of the Base XML file. You can read the Stream reader to read this XML.


Take a look at my codeplex project http://ip2html.codeplex.com/

It allows you to generate HTML from the given (InfoPath) XML & (XMLFormView) XSLT.


We ended up using the XmlFormHostItem.NotifyHost method to send HTML to a custom web part in a button-clicked event, which converted the HTML to PDF using Winnovative HTML to PDF converter.

HTML generation from InfoPath code-behind:

var formData = new XmlDocument();
var xslt = new XslCompiledTransform(true);

// Load the form data 
formData.LoadXml(MainDataSource.CreateNavigator().InnerXml);
// Extract the stylesheet from the package
xslt.Load(ExtractFromPackage("Print.xsl")); // (uses Template.OpenFileFromPackage(string fileName) to get xsl)

// Perform XSL-transformation
// [...]

// Send HTML to web part
this.NotifyHost(formData.InnerXml);

One drawback of this method is that the NotifyHost event only fires once per form, so if the user clicks 'Save as PDF' and then cancels, he must reload the form in order to be able to save as PDF.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜