What's New for InfoPath Developers

Microsoft Office InfoPath 2007 has added many new features and improvements that are of interest to developers. Foremost among these improvements is the addition of a new managed-code object model that is cleaner and better integrated with the .NET Framework. Business logic written against this new object model works the same way for a form template opened in Office InfoPath 2007 as it does for a form template opened in a Web browser.

Additionally, a new development environment for working with business logic written in managed code is integrated into Office InfoPath 2007, which is called Microsoft Visual Studio Tools for Applications (VSTA).

Microsoft Office Forms Server 2007, and the same forms functionality called InfoPath Forms Services available in Microsoft Office SharePoint Server 2007, provides a way to deploy an InfoPath form template to a server so that users without Office InfoPath 2007 can open and fill out InfoPath forms using a Web browser.

Using business logic written to the new managed object model, and by working with design checking features in InfoPath design mode, you can create a single form template that you can deploy to Office Forms Server 2007 or to an appropriately configured document library on Office SharePoint Server 2007 running InfoPath Forms Services. This form template will run in both InfoPath and in a Web browser.

The set of InfoPath client and InfoPath Forms Services features that support this design and deployment experience are referred to as design once.

New Features and Improvements

The following sections briefly describe these new Office InfoPath 2007 features and improvements that are of interest to InfoPath developers:

  • New Managed Code Object Model and Development Environments
  • COM Add-in Support
  • Form Template Converters
  • Custom Data Importers
  • Viewing Control IDs in the Design Mode User Interface
  • Data Connection Library Support
  • XML Events
  • Template Parts
  • The InfoPath Editor Hosted As a Control

New Managed Code Object Model and Development Environments

Office InfoPath 2007 provides a new managed-code object model with a core set of functionality for creating custom business logic in form templates. When deployed to Office Forms Server 2007 or to an appropriately configured document library in Office SharePoint Server 2007, business logic created using this new object model will run in both a Web browser and in Office InfoPath 2007.

Optionally, you can write business logic that uses an additional level of functionality available from this object model that will run only in form templates opened for editing in Office InfoPath 2007. Office InfoPath 2007 provides two new options for developing form templates that contain business logic written in managed code:

  • The development environment, which is integrated with InfoPath in a similar way to the Visual Basic Editor environment used by other Office applications. VSTA is a lightweight development environment based on functionality from Visual Studio.
  • Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System, which enables you to design an InfoPath form template and write business logic in managed code without leaving the Visual Studio environment.

For more information about the new object model and development environments, see About InfoPath Programming Environments.

COM Add-in Support

Office InfoPath 2007 provides support for creating and registering COM Add-ins using a development model that is very similar to other Office applications such as Word and Excel. InfoPath COM Add-ins support the IDTExtensibility2 interface for implementing methods that act as event handlers to respond to InfoPath startup and shutdown conditions. The ApplicationEvents object has been added to the InfoPath COM object model to provide support for application-level events such as the WindowActivate and XDocumentOpen events that allow you to create event handlers in your COM Add-in for InfoPath form window and document events.

To create an InfoPath Com Add-in, you need to implement the five events of the IDTExtensibility2 interface.

After you create an add-in, you must register it under the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\InfoPath\AddIns\ registry subkey and define the FriendlyName, Description, and LoadBehavior values. InfoPath COM Add-ins can be loaded by default when the application starts, or they can be invoked through the COM Add-Ins dialog box. To display the COM Add-Ins dialog box, click COM Add-Ins on the Tools menu.

Form Template Converters

Microsoft Office InfoPath 2003 with Service Pack 1 and later provide a framework for creating a new form template by importing the design of another kind of electronic form. Out of the box, Office InfoPath 2007 provides a converter for creating a new InfoPath form template based on the design of a form created in a Microsoft Office Word 2007 document or Microsoft Office Excel 2007 workbook. To start the process of importing the design of a form created in Word or Excel, on the File menu, click Import Form to display the Import Wizard. Office InfoPath 2007 has extended this framework to also support the creation and installation of custom converters for exporting the design of an InfoPath form template to another kind of electronic form. When a custom export converter has been installed, a user can open an InfoPath form template in design mode, and then on the File menu, click the Export Form Template command to export the form design to another type of electronic form.

Converter Interfaces  Form template converters specify a list of file types they support, and process those file types to output an InfoPath form template with manifest (.xsf), view (.xsl), and other files that constitute an InfoPath form template file (.xsn). An InfoPath form template converter is a standard COM automation component that implements the IFormTemplateConverter and IFormTemplateConverter2 interfaces. Implementing the IFormTemplateConverter interface provides compatibility with Microsoft Office InfoPath 2003. The IFormTemplateConverter2 interface provides additional functionality for users of Office InfoPath 2007. In order to be exposed in the InfoPath design mode, the converter also must provide some basic information about itself in the registry, including:

  • Display name
  • Verbose description
  • List of file extensions that the converter supports

The IPDESIGN.DLL dynamic link library in the C:\Program Files\Microsoft Office\Office12 folder provides the IFormTemplateConverter, IFormTemplateConverter2, IConversionManager, and IConversionManager2 interfaces for creating custom form design converters.

Automating a Converter  Form template converters can be automated to facilitate the bulk import or export of multiple form templates. To automate a converter, you use the methods implemented by the converter. For example, the following JScript snippet demonstrates how to automate the Microsoft Office Word Form importer to import "sample.doc".

  var oConverter = new ActiveXObject("InfoPath.DesignerWordImport.2");
var strSourcePath = "c:\\temp\\sample.doc";
var strDestPath = "c:\\temp\\sampleOutput\\"

oConverter.Initialize(); try { oConverter.SetLcid(1033); var strMessage = oConverter.Import(strSourcePath, strDestPath, true); } catch(e) { WScript.Echo("Error: " + e.message); }

WScript.Echo("Result was: " + strMessage);

oConverter.UnInitialize();

Custom Data Importers

Office InfoPath 2007 provides a framework for creating custom importers for importing data from other kinds of electronic forms and documents, as well as from paper forms and documents that are electronically scanned using Optical Character Recognition (OCR) software. To display the Import Form Data dialog box, click Fill Out a Form on the File menu, select the form to fill out, and then click Import Form Data on the File menu. The IPEDITOR.DLL dynamic link library in the C:\Program Files\Microsoft Office\Office12 folder provides the IInfoPathDataImporter, IInfoPathDataImporterFields, IInfoPathViewControl, and IPropertyBag interfaces which must be implemented to create a custom data importer.

Viewing Control IDs in the Design Mode User Interface

You can now determine the ViewContext identifier for a control on an InfoPath form in Design mode by displaying the control's Properties dialog box, and then clicking the Advanced tab. The ViewContext value for the current control is displayed in the Code section of the Advanced tab.

Data Connection Library Support

The data connection library is a list stored on an Office SharePoint Server 2007 or Office Forms Server 2007 server that contains data connection files. The data connection files stored in a data connection library can be either an Office Data Connection File (ODC), which is used by Excel, or a Universal Data Connection V2 File (UDC), which is used by Office InfoPath 2007.

Each UDC file contains data connection settings that can be used by an InfoPath form template. A UDC file in a data connection library can be used to define a data connection for a user form template (a user-deployed form template that does not contain code and other features that require administrator approval). All UDC files added to a data connection library require approval by a site collection administrator before they can be used. There is also a separate central store of UDC files that is controlled by the server farm administrator and can be used only by administrator-approved form templates (a form template that contains code and other features that do require administrator approval). A user form template requires two things to be true before it can make a cross-domain connection to a data source:

  1. The server farm administrator must first enable cross-domain data connections for user form templates throughout the entire server farm.
  2. Any cross-domain data connection must be defined in the data connection library.

By default, items in the data connection library require site administrator approval before InfoPath will use them.

When publishing to an Office SharePoint Server 2007 or Office Forms Server 2007 server, a form designer can choose one or more connections that are specified in the UDC files in a data connection library on the server in the same site collection. For server-based forms, the files must exist on the server to which the form will be published. The UDC files can contain server-specific information, such as alternative authentication information, or even a link to a server-specific connection.

When you design a form template and create a data connection to a data connection from a data connection library, InfoPath puts a link to the UDC file in the form template's manifest file (.xsf). Connection settings will be retrieved from the data connection library at runtime. This allows a server administrator to change the connection settings after the form has been deployed.

Specify a connection from a Data Connection Library in an existing form template  

  1. Open the form template in design mode.
  2. On the Tools menu, click Data Connections.
  3. Click Add to start the Data Connection Wizard, click Search for connections on a Microsoft Office SharePoint Server, and then click Next.

Specify a connection from a Data Connection Library when creating a new blank form  

  1. On the File menu, click Design a Form.
  2. In the Design a Form dialog box, click the Connection Library icon.

Specify a connection from a Data Connection Library for a List Box, Drop-Down List Box, or ComboBox control  

  1. Open the form template in design mode.
  2. Display the control's Properties dialog box.
  3. On the Data tab, click Look up values from an external data source, and then click Add.
  4. Click Search for Connections on a Microsoft Office SharePoint Server, and then click Next.

Specify a data connection from a Data Connection Library when configuring a form template submit options  

  1. Open the form template in design mode.
  2. On the Tools menu, click Submit Options.
  3. Click the Allow users to submit this form check box.
  4. Click Connection from a data connection library from the drop-down list.
  5. Click Add to start the Data Connection Wizard.

Specify a data connection from a Data Connection Library when configuring a form template to submit to a Web server using HTTP Post  

  1. Open the form template in design mode.
  2. On the Tools menu, click Submit Options.
  3. Click the Allow users to submit this form check box.
  4. Click Send form data to a single destination, and then select Web server (HTTP) from the drop-down list.
  5. Click Modify.
  6. In the Submit to a Web Server dialog box, click Office Server connection, and then click Server Connection.

Configuring Data Connection Library Authentication Settings on the Office SharePoint Server   A server administrator can control how certain features of authentication are performed for the connections specified in a data connection library on Office SharePoint Server 2007 or Office Forms Server 2007. The following table lists data connection library settings that are made in SharePoint 3.0 Central Administration, on the Application Management page, by clicking Configure Form Services.

Setting Description
Require SSL for HTTP authentication to data sources Forms that connect to back-end data sources such as Web Services may need to connect using Basic or Digest authentication, which require that a password be sent over the network. Check this box to require an SSL-encrypted connection for these authentication types. The default setting is True (selected).
Allow embedded SQL authentication Forms that connect to Microsoft SQL Server databases may embed the SQL Server username and password in the connection string. The connection string can be read in clear text in the UDC file associated with the form template, or in the form template manifest.xsf file. Uncheck this box to block forms from using embedded SQL credentials. The default setting is False (not selected).
Allow user form templates to use authentication information contained in data connection files Universal Data Connection (UDC) files can contain alternative authentication information, such as an explicit username and password, or a Single Sign-On application ID. Check this box to allow user form templates to use this alternate authentication information from UDC files. The default setting is False (not selected).
Allow user form templates to access data from another domain User form templates can contain data connections that access data from another domain. Check this box to allow user form templates to make cross-domain data access. The default setting is False (not selected).

XML Events

When users work with a form template created with Office InfoPath 2007 that has been deployed to Office SharePoint Server 2007 or Office Forms Server 2007, InfoPath stores and manipulates form data in memory using either of two methods depending on how the form template is opened:

  • When the form template is opened in InfoPath, the Microsoft XML Core Services 5.0 (MSXML5) DOMDocument object (accessed using the DOM property of the InfoPath XDocument object) is used.
  • When the form template is opened in a Web browser, the Microsoft .NET Framework 2.0 XmlDocument class is used.

By using the methods of the XPathNavigator class in conjunction with the classes and members of the new Microsoft.Office.InfoPath object model, form template developers are able to write managed code functions and subroutines that access and update XML data in both of these stores. XML events allow form developers to programmatically cancel, add validation, and define side effects for operations on XML nodes such as Insert, Delete, and ValueChange. Office InfoPath 2007 provides three core XML events when working with the new managed object model: the Changing, Validating, and Changed events.

Bb230087.vs_note(en-us,office.12).gif  Note
The Changing event is supported only in the business logic of a form template opened with Office InfoPath 2007. The Changing event is not supported in browser-enabled form templates opened in a Web browser.

Create an event handler for the Changing, Validating, or Changed event of a control  

Bb230087.vs_note(en-us,office.12).gif  Note
These event handlers cannot be created when the form template programming language is either JScript or VBScript, or is based on the InfoPath 2003 Compatible languages of Visual C# and Visual Basic, which use the Microsoft.Office.Interop.InfoPath.Semitrust namespace. See the documentation included with the Microsoft Visual Studio Tools for Applications (VSTA) environment for more information about working with event handlers, including the topic How to: Add an Event Handler. For more information on working with XML using the new managed code object model, see Working with XML in Managed Code Form Templates.

Template Parts

Form designers can now create libraries of form parts, called template parts, which can contain controls, layout, schema, rules, and calculations. You can deploy template parts to a shared repository or locally to a set of computers so that an individual or group of form designers can use them for the modular design of new form templates. For example, if you have a set of form templates that contain the same header section, you can use template parts to design the header section once, and then insert that header section into each of your form templates.

Additionally, you can later update the design of a template part and save it back to the shared repository. When the form designer re-opens a form template that contains the older version of your template part, InfoPath will notify the user that an updated version of the template part is available, and allow the user to update the part.

Because some InfoPath design features cannot be used in template parts, they have a distinct design mode. When you save a template part to the shared repository, it becomes available in the Custom Controls section of the Controls task pane in form template design mode. If you create a template part and save it locally, you must use the Add or Remove Custom Controls command to add the template part to the Controls task pane.

Create a Template Part  

  1. On the File menu, click Design a Form.
  2. In the Design a Form dialog box, click Template Part.
  3. In Based on, click the icon for the data source on which you want to base the template part, and then click OK.
  4. Design a template part as you would any other form template, inserting layout, controls, rules, and data validation. You can also add data connections to allow automatic population of Drop-Down List Box, Combo Box, or List Box controls.
  5. To save the template part, click Save on the File menu. The display name of the template part will be the same as the name of the file to which it is saved.
  6. In the Controls task pane, click Add or Remove Custom Controls, click Add, and then locate the InfoPath Template Parts (.xtp) file you saved.
  7. If you are using Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System, right-click in the Toolbox, and then click Choose Items, click Add, and then locate the InfoPath Template Part (.xtp) file you saved.

Use a Template Part  

  1. Create a new form template and open the Controls task pane.
  2. Scroll down to Custom controls, and drag your template part onto the form.
Bb230087.vs_note(en-us,office.12).gif  Note
If you are using Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System, template parts are listed at the end of the InfoPath section of the Toolbox.

You can now work with your form template and the template part within it just as you would when designing a form without a template part. All controls and associated logic can be edited. You can also edit the template part in its original file, and you will notice that where it had been previously inserted in other form templates, the template part will notify you that a new version is available.

Bb230087.vs_note(en-us,office.12).gif  Note
If you save updated template parts to the shared repository, you must close and re-open the form template into which you have inserted a template part before you will be notified that there is a new version available. If you save updated template parts to a local folder, you must reinstall the template part to all computers that share it.

The InfoPath Editor Hosted As a Control

The InfoPath form editing functionality has been factored into a set of properties and methods that are exposed through the InfoPathEditorObject object of the IPEDITOR.DLL dynamic link library. These properties and methods allow you to host a subset of InfoPath editing features from another application as an ActiveX control or a managed Windows Form control.

InfoPath setup also installs the Microsoft.Office.InfoPath.FormControl.dll assembly located in the C:\Program Files\Microsoft Office\Office12 folder, which wraps the InfoPathEditorObject object's COM object model for using the control in Windows Forms and other .NET applications.

Bb230087.vs_note(en-us,office.12).gif  Note
There are differences between the object model available using the InfoPathEditorObject object and the one available using the FormControl object.

The following table summarizes the properties and methods provided by the InfoPathEditorObject object:

Members Description
CloseDocument method Closes the open XML document.
DataConnectionBaseURL property Gets or sets the URL used for data connections.
FlushDocument method Saves or flushes the loaded document.
Host property Gets or sets the object used to access the object model of the host application. Set to null by default.
HostName property Gets or sets the name of the host application.
Load method Loads the specified XML document from the file system based on a URL to the file name. The XML file supplied must contain processing instructions (href and name attributes) that reference the form template used to load and edit the XML file.
LoadFromStream method Loads the specified XML document from a stream (IStream).
NewFromSolution method Creates a new InfoPath form document based on a URL to the specified form template.
NewFromSolutionWithData method Creates a new InfoPath form document using the specified XML data as an IStream and a URL to a form template file. When using this method, the XML file does not have to contain processing instructions that reference the form template used to load and edit the file.
SetInitEventHandler method Sets the function in the host application that is used as a callback function for the Initialize event, which is called before the InfoPath OnLoad event.
SetNotifyHostEventHandler method Sets the function in the host application that is used as a callback function for notifying the host application of changes.
SetSubmitToHostEventHandler method Sets the function in the host application that is used as the callback function when submitting data back to the host application. To configure the data connection for submitting to the host application, open the form template in InfoPath design mode, on the Tools menu click Submit Options, select the Allow users to submit this form check box, select Hosting environment in the drop-down list, and then click Add.
XDocument property Gets a DOM document object for working with members of the InfoPath object model.
Bb230087.vs_note(en-us,office.12).gif  Note
If you are working with the Microsoft.Office.InfoPath.FormControl assembly, this property is named XmlForm and gets an XmlForm object for working with members of the InfoPath object model.
Bb230087.vs_note(en-us,office.12).gif  Note
If you are working with the Microsoft.Office.InfoPath.FormControl assembly, this property is named XmlForm and gets an XmlForm object for working with members of the InfoPath object model.

InfoPath toolbars and menu bars are not supplied by the InfoPathEditorObject object by default; however, each command in the InfoPath editor menus and task panes are exposed through the IOLECommandTarget interface. The host application can then execute those commands through that interface, allowing a developer to replicate this functionality fully, partially, or not at all, if desired.

For information about working with InfoPath commands using the IOLECommandTarget interface, see the article titled "Hosting the Infopath Form Editing Environment in a Custom WinForm Application," which includes a link to a sample Visual Studio project, on the InfoPath Developer Portal on MSDN.

Add the InfoPath Editor control to a Windows Form application  

  1. Create a new Windows Application project.
  2. Add the InfoPath FormControl to the Toolbox as a .NET Framework Component (the Microsoft.Office.InfoPath.FormControl.dll assembly located in C:\Program Files\Microsoft Office\Office12).
  3. Drag the FormControl control onto your Windows form.
  4. Add a Button control to your Windows form.
  5. Write a Click event handler for the Button control that loads an InfoPath form XML file into the FormControl (for example, formControl1.New(@"C:\\hello.xml");)
  6. Build and run the application.

This assumes that an InfoPath XML file named "hello.xml" exists at C:\hello.xml.

In order to use the New method used in this example, the XML file must have processing instruction references using the href and name attributes that specify an InfoPath Form Template file (.xsn) in the header. If this is not possible, the NewFromFormTemplate(string, System.IO.Stream,Microsoft.Office.InfoPath.XmlFormOpenMode) method can be used to load XML from a System.IO.Stream, or you can use the NewFromFormTemplate(string) method if you have a .xsn file and a suitably structured XML file, but the XML file does not have processing instruction references that specify the .xsn file. The NewFromFormTemplate method of the FormControl object corresponds with the NewFromSolution and the LoadFromStream methods the InfoPathEditor object.