Showing posts with label InfoPath. Show all posts
Showing posts with label InfoPath. Show all posts

Wednesday, December 12, 2007

InfoPath: How to exit from a browser form and suppress the "save changes" dialog

If you create a browser-based InfoPath 2007 form and use a programmatic submission procedure instead of the built-in submit button, the user may get a "save changes?" prompt when clicking the Close button on the form's toolbar. There are several ways you could avoid this in InfoPath 2003. One would be to set the form's dirty bit to false using the setDirty() method. Another is to programmatically close the form with your own button. I have not seen code to do either of these things in 2007 with managed C# code. Here is my workaround:

Create a button on the form. Add a rule to the button that closes the form on click. Unhide the button when the user clicks your custom submit button.

Tuesday, December 4, 2007

InfoPath: How to programmatically switch the view

The view can be programmatically changed in C# managed code like this:

this.ViewInfos.SwitchView("
name of view");

InfoPath: How to display images in browser-based forms

Use the following method to add an image to a browser-based form in InfoPath 2007 using C# managed code:

Your image must be available somewhere by URL.
1. Add a rich text control to the form.
2. Add the following code to the form:

XPathNavigator ng = MainDataSource.CreateNavigator().SelectSingleNode("XPath to the binding of the rich text control", NamespaceManager);
ng.AppendChild("<img xmlns=\"http://www.w3.org/1999/xhtml\" src=\"URL of your image\" />");

This modifies the XML node of the rich text box, adding an XHTML image as a child.