Share via


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 and in 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 Microsoft 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 Microsoft 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.

To write business logic that will run when a form is opened in both a Web browser and in Office InfoPath 2007, select the Enable browser-compatible features only check box on the Design a Form Template dialog box when creating a new form template. To write business logic that can use additional functionality only when opened in Office InfoPath 2007, clear the Enable browser-compatible features only check box when creating a new form template. You can also change this setting after creating a form template, by clicking Change Compatibility Settings on the Design Checker task pane.

Office InfoPath 2007 provides two new options for developing form templates that contain business logic written in managed code:

  • The Microsoft Visual Studio Tools for Applications (VSTA) 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.

  • InfoPath design mode integration in Visual Studio Tools for Office, 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 Understanding InfoPath 2007 Object Models and Development 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. For more information about the IDTExtensibility2 interface, search for "IDTExtensibility2" on MSDN.

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 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

InfoPath 2003 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 document or Microsoft Excel workbook. To start the process of importing the design of a form created in Word or Excel, click Import Form on the File menu, 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 click the Export Form Template command on the File menu 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 which implements the IFormTemplateConverter and IFormTemplateConverter2 interfaces. Implementing the IFormTemplateConverter interface provides compatibility with Microsoft 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 (OCD), 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 InfoPath 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 cross-domain data access for user form templates that use connection settings in a data connection file

User form templates can contain data connections in a data connection files that accesses 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 Forms Server 2007 or Office SharePoint Server 2007, InfoPath stores and manipulates form data in memory using either of two methods depending on how the form template was opened:

  • When the form template is opened in InfoPath, the Microsoft XML Core Services 5.0 (MSXML5) DOMDocument 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 which 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.

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

  1. Open the form template in design mode.

  2. Right-click the control, click Programming, and then click the event you want to work with.

This will open the Microsoft Visual Studio Tools for Applications (VSTA) environment (or Visual Studio 2005 if you have it and Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System installed, or in Visual Studio 2008 with Visual Studio Tools for Office) and create an event handler skeleton similar to the following example for the Changed event in C#:

public void field1_Changed(object sender, XmlEventArgs e)
{
   // Write code here to change data outside the Main Data Object
   // such as other Data Objects and member variables.
   if (e.UndoRedo)
   {
      // InfoPath will handle all undo and redo operations that change
      // the Main Data Object, so there is nothing left for custom code
      // to do.
      return;
   }
    // Write code here to change the Main Data Object.
}

For more information on creating event handlers, see How to: Add an Event Handler. For more information on working with XML using the new managed code object model, see How to: Work with the XPathNavigator and XPathNodeIterator Classes.

Binding Events Using Delegates

When using the new managed code object model, Office InfoPath 2007 binds events to event handlers using delegates. Note that although InfoPath uses delegates for event binding, the functionality is a subset of typical managed code usage. Specifically, InfoPath uses delegates for static event binding. Binding can occur only in the InternalStartup method, which is executed when the form is loaded. If delegates for binding events are declared elsewhere in the code, a run-time exception is thrown.

The following shows the C# code that is generated by InfoPath when adding event handlers for the Changed event of field1 and the Validating event of field2. Note that event binding code for the event handler is added to the InternalStartup method using the XmlChangedEventHandler and XmlValidatingEventHandler delegates.

using System;
using Microsoft.Office.InfoPath;

namespace Template1
{
   public partial class FormCode
   {
      public void InternalStartup()
      {
         EventManager.XmlEvents["/my:myFields/my:field1"].Changed += new XmlChangedEventHandler(field1_Changed);
         EventManager.XmlEvents["/my:myFields/my:field2"].Validating += new XmlValidatingEventHandler(field2_Validating);
      }

      public void field1_Changed(object sender, XmlEventArgs e)
      {
         // Code for Changed event goes here.
      }

      public void field2_Validating(object sender, XmlValidatingEventArgs e)
      {
         // Code for Validating event goes here.
      }
   }
}

Important

The InternalStartup method and the event binding code within it are generated by InfoPath when you add event handlers using various user interface commands. You should not create the InternalStartup method or add any additional code within it yourself. For information about how to add event handlers, see How to: Add an Event Handler.

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. If you are using InfoPath and the Microsoft Visual Studio Tools for Applications (VSTA) development environment, in the Controls task pane, click Add or Remove Custom Controls, click Add, and then locate the InfoPath Template Parts (.xtp) file you saved.

    If you are using Visual Studio with InfoPath design mode integration, 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.

    Note

    If you are using Visual Studio with InfoPath design mode integration, 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.

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.

The following table summarizes the properties and methods provided by the InfoPathEditor 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.

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, click Submit Options on the Tools menu, 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 an XDocument object for working with members of the InfoPath object model.

NoteNote:
If you are working with 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 InfoPathEditor object out-of-the-box; 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. Start Microsoft Visual Studio.

  2. Create a new Windows Application project.

  3. 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)

  4. Drag the FormControl control onto your Windows form.

  5. Add a Button control to your Windows form.

  6. 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");)

  7. 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 InfoPathEditorObject object.

See Also

Other Resources

Developing InfoPath Managed Code Form Templates
Developing Managed Code Form Templates Using the InfoPath 2003 Object Model