In this week's “5 for forms” video demo, Trey Brumley, a software design engineer in test shows how you can use InfoPath to customize the form for an external list on SharePoint that connects to a SQL Employee database through Business Connectivity Services.
In this video demo, Phil Newman from the InfoPath program management team shares some tips and tricks for debugging InfoPath forms with sandboxed code on SharePoint server 2010.
Here is this link to the ULS viewer tool that is used in the demo:
Filters:
InfoPath provides two controls which saves pictures inside the XML form (rather than linking to it). When trying to process this XML file outside of InfoPath, you will need to translate the data back into the image binary. InfoPath picture control data and ink picture control data is stored in the XML as base64 encoded data. You will need to decode the base64 picture into binary before it is usable.
Below is a code sample in C# that will do it:
byte[] image = Convert.FromBase64String( s );MemoryStream memStr = new MemoryStream();memStr.Write( image, 0, image.Length );Image img = Image.FromStream( memStr );img.Save( filename );
Case Study #1
Problem: a form designer wants to use this logic:
IF (State="Ohio" or State="Alabama" or State="Arizona" or State="Georgia" or State="Utah" or State="Idaho" or State="Iowa") THEN (fail...)
Since the Validation UI only supports 5 statements, you run out of room before entering all of the tests.
Solution: Put more than one test in a statement. If you aren't sure of the syntax, follow along.
Enter the first three tests.
Click [OK] to close the dialog. Notice that the syntax is displayed in this dialog:
Click [Modify] and use this syntax.
When you change the first column to "The expression", you will see how to refer to the field you are checking. This differs depending on if you are checking the current field or a different field. In this case, State is the selected field, so we can enter the validation like this:
If you OK this and then come back to it, InfoPath will automatically break out the last 4 tests into separate statements. This makes it easier to see more of the conditions that are being evaluated.
Case Study #2
IF (State="Ohio" or State="Alabama") and TaxRate is blank THEN (fail...)
Using just the default Validation UI, you can't group tests like this.
Solution: Put more than one test in a statement. Again, if you aren't certain of the syntax, enter the tests in the Validation dialog:
Click [OK] to close. Note the syntax in this dialog:
Click [Modify], and use the syntax shown in the Validation statements.
Alternative Approach
Another way to handle both of these scenarios is to use multiple validations:
This will work and in some cases would be easier to follow (the 50 states could be listed and you could scroll the Validations).
Performance may be better in one or the other, but that would depend on the logic you are validating.
All of these statements are evaluated. There is not an implied "and" or "or" combining them. In this last example, if you were checking the "State = ... OR TaxRate is blank", both would fail. You could check the number of errors and would get 2, even though only 1 error message would be shown (the first one).
Jerry ThomasSoftware Design Engineer in Test
InfoPath’s custom control support allows users to create controls for three different types of binding:
Simple data type (string, numbers, etc)
Controls that are written to bind to simple data types would allow a control to do custom processing on data before it gets put into the XML. The control can be designed to have UI that combines multiple simple controls (buttons, textboxes, checkboxes, etc…) to encapsulate them into one control. For example, multiple buttons can be combined with a textbox to make an in-document calculator control. Combining these all into one control will provide a simple way to re-use the same control in multiple forms.
XML stream
InfoPath SP-1 allows XML nodes to follow any schema. This allows form developers to work with industry standard XML Schemas. One example is a MathML control that could be written for InfoPath to save XML compliant with the MathML schema and display it in InfoPath form in a meaningful manner.
IXMLDomNode
For greater flexibility, InfoPath custom controls can be bound to an IXMLDomNode and any msxml operations can be performed directly on the XML tree.
Deployment
Custom controls need not be installed on every form users’ computer before loading the form. Controls can be packaged with your form solution so that on first open, the control will be registered and installed. Controls should be stored in a CAB files and able to self-register.
Security
Custom controls in InfoPath have a few security constraints to keep users safe. Firstly, all custom controls used within InfoPath require the IObjectSafety interface to be implemented and the control to be marked as Safe for Scripting and Safe for Initialization. Without these two flags, InfoPath will not load the form and will notify the user.
In addition, for solution which have controls packaged in the form solution, it is necessary to sign the CAB files with a digital signature. When users open the form for the first time, they will be prompted on whether or not they will accept the control signed with that signature (similar to the ActiveX control dialogs you see in Windows 2k/XP).
For detailed information on how to write a custom control for InfoPath, see Lab 06 in the MSDN InfoPath 2003 Training. (http://msdn.microsoft.com/library/en-us/odc_ip2003_tr/html/odc_INF_Lab_06.asp)
When adding a web service data connection to an InfoPath 2003 form template, there is a bug that will cause InfoPath 2003 to disappear if the web service’s WSDL contains a particular recursive schema construct. The following snippet of XSD illustrates the issue:
<xs:element name="RecursiveRoot">
<xs:complexType>
<xs:sequence>
<xs:element name="Branch1" minOccurs="0">
<xs:element ref="ns:RecursiveRoot " maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="Branch2" minOccurs="0">
<xs:element ref="ns:RecursiveRoot" maxOccurs="unbounded" />
This XSD contains a recursive structure in which there is more than 1 path of recursion and the recursive root is not marked as an optional element in the XSD when referenced. InfoPath 2003 will work with the WSDL containing this XSD as expected if both references to RecursiveRoot were optional as illustrated in the following modified XSD (changes in red).
<xs:element ref="ns:RecursiveRoot " maxOccurs="unbounded" minOccurs="0"/>
<xs:element ref="ns:RecursiveRoot" maxOccurs="unbounded" minOccurs="0"/>
If you are having issues with a web service that you own, one work around to this issue with InfoPath 2003 is to modify the WSDL for your web service as shown above. In the case that this is not an acceptable work around, or you do not own the web service, the following steps will help you work around the problem:
1. Download the WSDL file for the web service to your local machine
2. Modify the XSD in the WSDL as shown above
3. Add a Data Connection to the local version of the WSDL file
If you are setting up a submit or receive/submit web service connection then the following steps are required as well to ensure that the data InfoPath submits to the web service adheres to the original schema:
4. File --> Extract Form Files to save your form template in an uncompressed format
5. Remove the modifications made to the WSDL XSD in the copy of the XSD that was added to the form template
If you modify the data connection or add another data connection to this local WSDL file for a submit web service then steps #4-#5 will have to applied again. If you expect other users to modify the design of this form template then the local version of the WSDL should be stored in a shared location that all designers have access to.
This issue has been reported to the InfoPath team as occurring in the ItemLookup method of the web services that Amazon exposes (http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl). In the case of this method, the modification that is necessary to avoid the InfoPath 2003 bug (step #2) is the following:
1. Find the BrowseNode element that contains references to other BrowseNode elements
2. Add minOccurs=”0” to the BrowseNode references (these occur under the “Children” element and the “Ancestors” element)
Since ItemLookup is a receive only method, there is no need to modify the form template files by hand (steps #4 and #5).
The InfoPath team is excited to announce the release of the Office 2010 and SharePoint Server 2010 public betas! For the 1st time members of the public can download InfoPath 2010. Download it now from www.microsoft.com/2010!
Here are just some of the highlights in this new release. (For more details, see our earlier What's New in InfoPath 2010 post).
Quick and Easy Form Design
SharePoint IntegrationOver the past 3 years of product development, we’ve made huge investments in integration with the SharePoint platform to make it much easier to build rich forms-based applications on top of SharePoint Server 2010.
Introduced since the technical preview, InfoPath now supports connecting to REST Web Services.
Go download the beta now and send us your feedback using Send-a-Smile.
Enjoy!
The InfoPath Team
Q: I want to create a control for entering passwords in an InfoPath form. How do I do this?
A: InfoPath cannot guarantee the security and privacy of text entered into a password control, so it does not contain such a control.
But Why?
A typical password control contains features that make it hard for anyone but the user typing the password to discover what that text is. Password controls may also interact with a secure server so that the password is not sent in clear text, but is instead encrypted. Further, copying the text from a password control is not allowed.
Because InfoPath allows files to be stored to a user’s local file system, InfoPath will the store the value typed into a field along with the XML. Additionally, InfoPath does not perform encryption of network traffic, meaning field values used as passwords will always be sent in clear text.
But I still want a password control
For the above reasons, we discourage using the contents of a field in an InfoPath form for entering and submitting passwords. Additionally, modifying the files used to create an InfoPath view to use the standard HTML password control (e.g. <INPUT type=”password” ID=”MyPassword”>), will not work in InfoPath. The nearest behavior that can be achieved is to format an InfoPath Text Box control to use a symbol font set, such as WebDings or WingDings so that the text being entered cannot easily be read as it is being typed.
When a custom Document Information Panel is associated with an Office document and/or template, the information needed to locate the Panel is contained in a custom XML data part stored with the document.I won’t go into the details of the way an Office Open XML document is structured here (needless to say there are many great resources for this on the web), but the format is basically a ZIP file with a collection of XML files that describe the contents of the word processing, spreadsheet, or presentation. Those XML files are linked to each other via logical “relationships” that define the necessary semantics (e.g. that one file contains the content for the header).
In the terms familiar to the Office Open specification, a custom XML data part is stored at the following location in an Office Open XML document:
Basically, the data is stored in an XML file which is logically related to the main part for that file type, and whose logical relationship is of type “customXml”.Now then, the other half of the definition of a custom Document Information Panel is the content of that custom XML data part. Here’s an example of the data stored in the custom XML data part for a custom Document Information Panel:
<customPropertyEditors xmlns="http://schemas.microsoft.com/office/2006"> <showOnOpen> true </showOnOpen> <defaultPropertyEditorNamespace> http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-10-21T21:12:27 </defaultPropertyEditorNamespace> <customPropertyEditor> <XMLNamespace> http://schemas.microsoft.com/office/infopath/2003/myXSD </XMLNamespace> <XSNLocation> \\contoso-server\forms\assetForm.xsn </XSNLocation> </customPropertyEditor></customPropertyEditors>
This part defines the settings for the Document Information Panel by using the following four elements:
The contents of this element are one of two choices:• Standard properties – this setting shows the default Office 2007 property template• <custom XML namespace> - if the template to be shown should be a custom Document Information Panel stored with the document, its root XML namespace is stored in this element, so Office can locate and display this information automatically when the Document Information Panel is shown
With that information defined, Office automatically locates a custom Document Information Panel and displays it as requested. Note that none of these steps involve using Office to set up the Document Information Panel – this process can be automated without Office (for example, to add a Document Information Panel to a template as part of a server-based process).
Alnur AliProgram Manager
Q: How do I get the red asterisk to show on a Rich Text Box? There isn’t a checkbox for “Cannot be blank” on this type of control!
A: Easy - add a declarative data validation rule for the condition where the field bound to the Rich Text Box “is blank”. To get started, display the control’s properties dialog box and then click Data Validation.
So now you’re wondering – why isn’t there a simple checkbox for that?
Behind the scenes, the “cannot be blank” checkbox actually maps to a change in the schema, rather than a declarative validation rule. For strings we add a length restriction, but for other types it sets nillable="true" (can be blank) or nillable="false" (cannot be blank).
This explains why the checkbox is enabled when using a schema you’re creating in InfoPath and disabled when using a fixed schema from an external source. Since the schema we use for rich text (XHTML) nodes is a complex type the nillable approach doesn’t apply.
So why does a declarative validation rule cause a red star to appear? When the form is running, the validation display semantics don’t distinguish between schema validation, declarative validation, and even code validation if you use an OnValidate event handler and/or add to the Errors collection. The logic for the validation display is:
if( node fails validation )
{
if( string value of node is blank )
show red star
}
else
show red border
There's been lots of well-deserved hype lately around Web 2.0 and the technology that's fueling it, AJAX. We're receiving lots of questions such as "do InfoPath browser forms support AJAX?". The answer is more complex than just yes :-); this article aims to clarify any ambiguities here. But first, some definitions.
What is AJAX?
Definition from Wikipedia: Ajax, shorthand for Asynchronous JavaScript and XML, is a web development technique for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user makes a change. This is meant to increase the web page's interactivity, speed, and usability.
What is a postback?
After a page has been loaded, a postback is defined as a subsequent browser request to the web server. Ajax is about asynchronous postbacks - those that allow the user to continue working with the page while the refresh happens.
Does InfoPath Forms Services use AJAX?
For a broad set of user actions while editing the form, there will be no postback to the server at all - way faster than an asynchronous postback – and the HTML will be incrementally updated, with no flash. This is because InfoPath Forms Services is capable of translating the declarative logic you've placed in the form into dynamic JavaScript snippets.
Such client-side operations work for actions such as inserting and deleting sections or table rows, conditional visibility or formatting, validation errors, calculations, firing rules to modify data, etc.
Cases where postback will occur have one thing in common: there's something that absolutely cannot be evaluated on the client, and thus has to be sent to the server for evaluation. For example:
- there is managed code in the form which needs to run (e.g. AfterChange event)
- there are complex XPath expressions used for a calculation, condition for a rule etc
When postback does need to happen it generally uses an XMLHTTP postback out-of-band; it does not involve a full page postback. The HTML can therefore be incrementally updated.
How can I tell when the postbacks will happen?
We'll only touch on this subject very briefly - expect more content on this soon. InfoPath Design Checker, in conjunction with InfoPath Forms Services, will provide you insights on the user actions that will cause a postback. It will also provide suggestions as to how to avoid these postbacks. Here's how to see these suggestions:
1. Make sure that your form template is browser-enabled by going to Tools | Form Options | Compatibility, and checking "Design a form template that can be opened in a browser or in InfoPath".
2. In the same dialog, provide a URL to a server running InfoPath Forms Services:
3. At the bottom of the Design Checker task pane, click Options, then check the "Show Browser Optimization Messages" checkbox:
4. Observe the postback optimization messages in the design checker task pane:
We'll follow-up with a separate article on ways to interpret these messages, and tips and tricks around improving form postback experience.
AJAX and forms hosted in a custom ASPX page
You can create custom ASPX pages hosting the InfoPath form control (XmlFormView; more on it here). Everything within the form still uses the above AJAX architecture. But if you need code-behind the page to communicate between the InfoPath form and other ASP.NET controls in the page, then those events will trigger a full-page postback.
Office Forms Services and ASP.NET AJAX framework
In MOSS 2007, we don't offer integration with the ASP.NET AJAX framework (also known as Atlas) to allow for partial postbacks involving communication with other ASP.NET controls in the page. Another thing to note is that InfoPath XmlFormView control will not work inside an ASP.NET AJAX UpdatePanel. At this point, there is no workaround to make it work. Integration with the ASP.NET AJAX is a frequent customer request; we're carefully considering it for future releases.
Check out the new Capacity Management Resource Center for SharePoint 2010 that went live when Office 2010 released to manufacturing last Friday, April 16th. The InfoPath capacity planning document along with a refresh of the Capacity Planning Tool Kit are now available.
The Capacity Management Resource Center contains resources to help you with capacity management in your Microsoft SharePoint Server 2010 environment—map your solution design to a farm size and set of hardware that supports your business goals.
This week’s cool form displays your local weather forecast by using a REST Web Service data connection to pull in weather information from an online weather service. There are two views to the form, one minimal and one extended. The form contains linked picture controls that use rules to concatenate the Web service data and generate a URL pointing to images on the weather site. By hosting this form inside the InfoPath form Web part, you can display the latest weather forecast information on your SharePoint portal pages.
Minimal View:
Extended View:
For more information about using REST Web Service data connections with InfoPath forms, see our earlier blog post http://blogs.msdn.com/infopath/archive/2010/02/11/add-a-dynamic-map-to-a-contact-form-using-rest-web-services.aspx.
If you have a “cool” form that you would like to share with us, please send an e-mail with the following details to coolform@microsoft.com -
The most popular submissions will be featured on our blog in future posts.
Check out other Cool Forms here.
How to Enqueue Submits While Offline
Applies to: Microsoft Office InfoPath 2003 SP1
Scenario:
User fills out forms for a particular form template while the laptop is disconnected from the network. Upon reconnection, seamlessly syncrhonize the offline forms to a Windows SharePoint Services form library.
Solution:
Using OnSubmitRequest, you can have the code save to the offline folder depending on if we're offline or not, as in the following code, which is written in C# using our Visual Studio .NET Toolkit. You will also need to add a project reference to System.Xml.dll and the using System.XML; directive to your form code.
public void OnSubmitRequest(DocReturnEvent e)
Then, if you've been offline for a while and a number of files have built up, you can run the following jscript to invoke InfoPath externally and force a submit looping through the files, as below:
The Microsoft Office InfoPath Team is interested in seeing how you are using InfoPath. We would like you to send us your InfoPath forms so we can review them and collect data on how you are using the forms. We will be using these forms to implement improvements in future versions of Microsoft Office InfoPath. We are interested in looking at a variety of forms ranging from simple to complex (in terms of length, rules, data connections, code, etc.).
Please send us your forms at ipforms@microsoft.com and include a brief description of how the form is used, what is working well for you and any suggestions for improvement. Also let us know if we can contact you with any follow up questions.
We cannot guarantee that every form will be reviewed or that the confidentiality of the forms or information contained therein will be maintained. We ask that you not submit forms containing confidential information. Thank you for your submissions. We look forward to hearing from you.Microsoft Office InfoPath Team
The InfoPath hosted control gives developers of third party hosted applications the ability to respond to events in the form. The InfoPath event manager provides this functionality. Through the event manager a host application can respond to 5 form events, 3 xml events and 1 control event:
Form Events
Xml Events
Control Events
Saving eventContext Changed eventSign eventMerging eventView Switched event
Changing eventValidating eventChanged event
Clicking event
How can third party host applications use the event manager?
Step 1: Implement an InternalStartup method
First, add code to handle the InternalStartup event. InternalStartup method will execute when a form loads.
public Form1() { InitializeComponent(); //sync to the startup event where you can register for individual events formControl1.InternalStartup += new Microsoft.Office.InfoPath.FormControl.EventHandler<EventArgs>(InternalStartup); }
Next, implement your InternalStartup method. The function signature should look similar to:
void formControl1_InternalStartup(object sender, EventArgs e)
Step 2: Register to receive events
In your InternalStartup method add code to register for events. For form events this code looks like this.
void InternalStartup(object sender, EventArgs e) { ((FormControl)sender).EventManager.FormEvents.ViewSwitched += new ViewSwitchedEventHandler(OnSwitchView); ((FormControl)sender).EventManager.FormEvents.Submit += new SubmitEventHandler(OnSubmit); ((FormControl)sender).EventManager.FormEvents.Sign += new SignEventHandler(OnSign); ((FormControl)sender).EventManager.FormEvents.Save += new SaveEventHandler(OnSave); ((FormControl)sender).EventManager.FormEvents.Merge += new MergeEventHandler(OnMerge); }
For xml events you must provide the XPath of the node whose events you wish to respond to. Below is a sample of how to register to receive xml events.
void InternalStartup(object sender, EventArgs e) { ((FormControl)sender).EventManager.XmlEvents["/my:myFields/my:field1"].Changed += new XmlChangedEventHandler(FieldChanged); ((FormControl)sender).EventManager.XmlEvents["/my:myFields/my:field1"].Changing += new XmlChangingEventHandler(FieldChanging); ((FormControl)sender).EventManager.XmlEvents["/my:myFields/my:field1"].Validating += new XmlValidatingEventHandler(FieldValidating); }
To receive the click event for a button you must specify the control id of the button. Below is a sample of how to register to receive control events.
void InternalStartup(object sender, EventArgs e) { ((ButtonEvent)((FormControl)sender).EventManager.ControlEvents["CTRL2_5"]).Clicked += new ClickedEventHandler(ButtonClicked); }
Step 3: Implement methods to handle each event registered
The final step is to implement handlers for the events you have registered for.The handlers for the events have the following method signatures.
public delegate void ViewSwitchedEventHandler(object sender, Microsoft.Office.InfoPath.ViewSwitchedEventArgs e) public delegate void SubmitEventHandler(object sender, Microsoft.Office.InfoPath.SubmitEventArgs e) public delegate void SignEventHandler(object sender, Microsoft.Office.InfoPath.SignEventArgs e) public delegate void SaveEventHandler(object sender, Microsoft.Office.InfoPath.SaveEventArgs e) public delegate void MergeEventHandler(object sender, Microsoft.Office.InfoPath.MergeEventArgs e)
public delegate void XmlChangedEventHandler(object sender, Microsoft.Office.InfoPath.XmlEventArgs e) public delegate void XmlChangingEventHandler(object sender, Microsoft.Office.InfoPath.XmlChangingEventArgs e) public delegate void XmlValidatingEventHandler(object sender, Microsoft.Office.InfoPath.XmlValidatingEventArgs e)
public delegate void ClickedEventHandler(object sender, Microsoft.Office.InfoPath.ClickedEventArgs e)
Example: changed event, view switched event, button clicked event.
void FieldChanged(object sender, XmlEventArgs e) {} void OnSwitchView(object sender, ViewSwitchedEventArgs e) {} void button1_Click(object sender, EventArgs e) {}
Things to know about handling events
DeVere DyettSoftware Design Engineer in Test
We on the InfoPath team are delighted to announce the release of Microsoft InfoPath 2010 (Technical Preview). We’re really excited to share all of our great new features with you!
(Click the thumbnails for higher-resolution images.)
Highlights
Where do I sign up?The Office 2010 Technical Preview is a limited-availability release. To sign up to be considered for the Office 2010 Technical Preview program:
How do I win the Xbox?
Contest is limited to eligible members of the InfoPath 2010 Technical Preview program referenced above, and additional limitations may apply. All submissions will be reviewed by the InfoPath team, and prizes will be awarded in several categories, including best overall solution, best video, and best bug. Contest details will be posted on the technical preview site at http://connect.microsoft.com.
We will post more details on our new features in the coming weeks. Stay tuned!
This week’s cool form is a feature request issue tracking list used by the Visio team. It’s divided into two main sections, the separate status section allows readers to jump directly to the information they care most about. It uses picture buttons to allow selection between ‘Office 14’ and ‘Office 15’ and to show which one is currently selected. This form also dynamically generates the proper direct link to the bug database based on the bug ID that is entered.
In this short video demo, Matt Bielich from the InfoPath test team shows how you can add a rating control to your InfoPath 2010 forms using picture buttons.
The option to “Submit as Email” doesn’t include the form in the body of the mail, so here’s another way to encourage your form-fillers to send their forms as email and include that body.
This script could be used in a Blogger form to turn on the Mail Envelope when the user switches to the “Email” view. That event could be triggered by the form-filler using the View menu, or even by a Rule on a button. It also makes some decisions based on the user’s current role so you can see how to do that.
function XDocument::OnSwitchView(eventObj) {
var mail = XDocument.View.Window.MailEnvelope;
if (XDocument.View.Name == "Email") {
// get nodes from DOM
var blog = XDocument.DOM.selectSingleNode("/dfs:myFields/dfs:dataFields/d:blog");
var id = blog.selectSingleNode("@ID");
var title = blog.selectSingleNode("@Title");
var blogger = blog.selectSingleNode("@BloggerName");
var replies = blog.selectNodes("d:reply/@ReplyName");
// Set To field to include blog and the original blogger
mail.To = "blog; " + blogger.text;
// Set CC field to include all the replies (minus the current one)
if (replies != null) {
var cc = "";
for (var i = 0; i < replies.length - 1; i++) {
cc += replies(i).text + "; ";
mail.CC = cc;
// Set subject to look like a thread
var subject = "Blog " + id.text + " - " + title.text;
if (XDocument.Role != "Create")
subject = "RE: " + subject;
mail.Subject = subject;
// Show the mail envelope
mail.Visible = true;
else {
mail.Visible = false;