About Programming InfoPath
Microsoft Office InfoPath 2007 provides developers with a rich development environment for customizing forms. Forms can be customized by writing programming code to respond to form and data validation events, to access and manipulate a form's underlying XML document, to implement custom data submission and merges, and to implement access to external data sources. Customizing a form can also involve altering one of the form files to suit a specific requirement.
It is important to understand a few key concepts that are involved in programming an InfoPath form. These concepts include the InfoPath programming components, programmatic and declarative programming, the InfoPath programming languages, and the InfoPath programming environment.
InfoPath programming components
InfoPath programmability involves customizing an InfoPath form by altering its form files or by writing scripting code to create custom functions using the InfoPath object model. The main components of an InfoPath form that can involve programmatic interaction are listed in the following table.
|Object model||A robust, hierarchical type library composed of collections, objects, properties, methods, and events that give form developers programmatic control over various aspects of the InfoPath editing environment and access to a form's underlying XML document.|
|Data validation||A combination of XML Schemas, expressions, and scripting code used to validate and constrain the data that users are allowed to enter in a form.|
|Event handling||A set of event handlers that respond to changes to a form's underlying XML document, respond to view switching, implement custom form submission, or respond to the loading of the form's underlying XML document.|
|User interface||A set of customizable user interface components that includes menus, toolbars, buttons, command bars, and a task pane.|
|Editing controls||A set of InfoPath-specific controls used to manage and interact with the form's underlying XML document that includes collections, optional items, text lists, and fields. Note that you do not interact with the controls directly, but rather through the form's underlying XML document to which the controls are bound.|
|Error handling||A combination of event handlers, object model calls, and form definition (.xsf) file entries that are used to handle errors in an InfoPath form.|
|Security||A set of security levels that restrict access to the InfoPath object model and system resources.|
|Data submission||A set of predefined functions that can be used to implement custom posting and submission functionality for an InfoPath form.|
|Business logic||A set of custom scripting files that contain programming code used to implement specific editing behavior, data validation, event handlers, and control of data flow. Business logic can also include accessing of external Component Object Model (COM) components.|
|Form integration||Integration of other Microsoft Office applications such as Microsoft Excel or Microsoft Outlook. Integration may also involve the use of back-end servers such as Microsoft SQL Server, Microsoft Windows SharePoint Services, or XML Web services.|
Programmatic and declarative development
When you alter the InfoPath form files, you customize the form declaratively—that is, you open the form files in some type of standard text editor and manually change the elements, attributes, and values of the files. When you alter a form programmatically, you write programming code using a scripting language or a managed code language, in conjunction with the InfoPath object model and, in some cases, Component Object Model (COM) components, to extend and enhance form behavior.
The following are some of the ways in which a form may be customized declaratively:
- Modifying the XML Schema (.xsd) files
- Modifying the view (.xsl) files created in design mode
- Modifying the form definition (.xsf) file
- Modifying the XML template (.xml) file
The following are some of the ways in which a form may be customized programmatically:
- Adding form lifecycle processing logic
- Adding custom data validation
- Adding custom error handling
- Implementing data submission
- Responding to a form merge (or import)
- Using custom task panes
- Using custom dialog boxes
- Accessing and modifying a form's underlying XML document
- Accessing and modifying the form definition file
- Using external COM components
InfoPath programming languages and the programming environment
Like other Microsoft Office applications, InfoPath provides a programming environment and programming languages that developers can use to automate and extend their Office applications. However, while most Office applications use Microsoft Visual Basic for Applications (VBA) as their primary programming language, InfoPath uses two scripting languages—Microsoft JScript and Microsoft VBScript, and two managed-code languages, Microsoft Visual C# and Microsoft Visual Basic. In addition, the programming environment that is used when writing script code in InfoPath is the Microsoft Script Editor (MSE), not the Visual Basic Editor, and the enviroment included for writing manged code is Microsoft Visual Studio Tools for Applications (VSTA), which can be installed when the Microsoft .NET Framework 2.0 and Microsoft Core XML Services 6.0 are present.