Introduction to customizing form templates by using programming code

Microsoft Office InfoPath provides developers with a rich development environment for customizing form templates. Form templates can be customized by writing programming code that responds to form and data validation events, accesses and manipulates the underlying XML document for a form, implements custom data submission and merges, and accesses external data sources. Customizing a form template can also involve altering one of the form template files to meet a specific requirement.

It is important to understand a few key concepts that are involved in programming a form template. These concepts include the InfoPath programming components, declarative and programmatic programming, and supported programming languages and environments.

In this article

Programming components

Declarative and programmatic development

Programming languages and environments

Programming components

InfoPath programmability involves customizing a form template by altering its source files or by writing script to create custom functions that use the InfoPath object model. The main components of a form template that can involve programmatic interaction are listed in the following table.



Object model

A hierarchical type library composed of collections, objects, properties, methods, and events that give form template 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 task panes.

Editing controls

A set of InfoPath-specific controls used to manage and interact with a form's underlying XML document, which includes collections, optional items, and fields. Note that you do not interact with these editing 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 a form.


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 a 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 programs such as Microsoft Office Excel or Microsoft Office Outlook. Integration may also involve the use of back-end servers such as Microsoft SQL Server, Microsoft Windows SharePoint Services, or XML Web services.

Top of Page

Declarative and programmatic development

When you alter form template files, you customize the form template declaratively — that is, you open the files in a standard text editor and manually change the elements, attributes, and values of the files. When you alter a form template programmatically, you write programming code by using a scripting language or a managed code language, in conjunction with the InfoPath object model and, in some cases, COM components, to extend and enhance the behavior of a form template.

The following are some of the ways that you can customize a form template declaratively:

  • Modify the XML Schema (.xsd) files

  • Modify the view (.xsl) files created in design mode

  • Modify the form definition (.xsf) file

  • Modify the XML template (.xml) file

The following are some of the ways that you can customize a form template programmatically:

  • Add form lifecycle processing logic

  • Add custom data validation

  • Add custom error handling

  • Implement data submission

  • Respond to a form merge or import

  • Use custom task panes

  • Use custom dialog boxes

  • Access and modify a form's underlying XML document

  • Access and modify the form definition (.xsf) file

  • Use external COM components

For detailed information about the InfoPath programming components and customizing a form template either declaratively or programmatically, see the InfoPath Developer's Reference, which is installed with InfoPath and can be accessed from InfoPath Help in design mode.

Top of Page

Programming languages and environments

Like other Microsoft Office programs, InfoPath supports several programming environments and programming languages that developers can use to automate and extend Office programs. However, while most Office programs use Microsoft Visual Basic for Applications (VBA) as their primary programming language, InfoPath uses two scripting languages — Microsoft JScript and Microsoft Visual Basic Scripting Edition (VBScript), and two managed-code languages, Microsoft Visual C# and Microsoft Visual Basic. In addition, the programming environment that is used when writing script in InfoPath is the Microsoft Script Editor (MSE), not the Visual Basic Editor. Finally, the environment included for writing managed code is Microsoft Visual Studio 2005 Tools for Applications (VSTA), which can be installed when the Microsoft .NET Framework 2.0 and Microsoft Core XML Services 6.0 are present.

Top of Page

Applies To: Office 2010

Was this information helpful?

Yes No

How can we improve it?

255 characters remaining

To protect your privacy, please do not include contact information in your feedback. Review our privacy policy.

Thank you for your feedback!

Change language