Understanding InfoPath Object Models and Development Environment
Applies to: InfoPath 2010 | InfoPath Forms Services | Office 2010 | SharePoint Server 2010 | Visual Studio | Visual Studio Tools for Microsoft Office
Microsoft InfoPath 2010 supports two kinds of programming models for developing business logic in form templates, and also supports external automation from managed code.
InfoPath Forms Services, which is available in Microsoft SharePoint Server 2010, provides a Web browser experience for filling out InfoPath forms. When deployed to a server that runs InfoPath Forms Services, forms that are based on browser-compatible form templates (.xsn) can be opened in a Web browser from computers that do not have InfoPath 2010 installed, but they will open in InfoPath 2010 when it is installed. InfoPath Forms Services also provides an object model for automating server tasks related to InfoPath form template publishing and administration.
InfoPath 2010 supports the Microsoft Visual Studio Tools for Applications programming environment and its associated programming languages, which are described later in this topic.
InfoPath Programming Models
InfoPath 2010 supports two object models for developing business logic in form templates:
The InfoPath Managed Code Object Model
The InfoPath 2003-Compatible Managed Code Object Model
Additionally, InfoPath 2010 enables writing managed code to automate InfoPath from an external application.
InfoPath Forms Services provides an object model for automating server tasks, such as verifying and uploading form templates from code running on the server, which requires server administrator access and permissions.
Note
The InfoPath Filler 2010 can open and run InfoPath form template solutions created in earlier versions of InfoPath that use business logic written with scripting languages (JScript and VBScript). However, InfoPath Designer 2010 does not support creating or modifying form templates that use business logic written with script.
The InfoPath Managed Code Object Model
The InfoPath 2010 managed code object model is implemented in two assemblies both of which are named Microsoft.Office.Infopath.dll.
One version of the assembly implements a subset of the InfoPath object model that contains only the types and members that are supported in the business logic of form templates deployed as browser-enabled form templates running on Microsoft SharePoint Server 2010 with InfoPath Forms Services. Form templates with business logic written against this assembly will open and run in the InfoPath Filler and in a Web browser.
The other version of the assembly implements additional types and members that provide functionality that is not supported in the business logic of browser-enabled form templates. Form templates with business logic written against the additional classes and members in this assembly will open and run only in the InfoPath Filler editor.
Note
It is possible to write conditional logic that uses the properties of the Environment class to determine which environment (InfoPath Filler or a Web browser) the form template is running in. By using this conditional logic, your business logic can branch between code that works in a Web browser and code written against classes and members that work only in the InfoPath Filler editor. For more information, see How to: Write Conditional Logic That Determines the Run-time Environment
The assembly that InfoPath uses when you add and compile business logic for the form template depends on whether you select the Blank Form or Blank Form (InfoPath Filler) form template on the New tab of the Microsoft Office Backstage when you start to design a new form in the InfoPath Designer. Forms created by using the Blank Form form template use the assembly that contains only the types and members that are supported in the business logic of form templates deployed as browser-enabled form templates. Forms created by using the Blank Form form template can be opened in both the Web browser and the InfoPath Filler. Forms created by using the Blank Form (InfoPath Filler) form template use the assembly that implements additional types and members that provide functionality that is not supported in the business logic of browser-enabled form templates, and can only be opened in the InfoPath Filler.
Tip
After you start to design a form template, you can change which assembly is used by changing the form's compatibility settings. To do that, click Language on the Developer tab, and then click Compatibility in the Category list. In the Form type list, select Web Browser Form to create a form that can be deployed as a browser-compatible form on Microsoft SharePoint Server 2010. Select InfoPath Filler Form to create a form that can run only in the InfoPath Filler editor. The other selections in the Form type list provide support for compatibility with InfoPath 2007 and InfoPath 2003.
The classes and members of both versions of this object model are exposed through the Microsoft.Office.InfoPath namespace. These assemblies are located in the following directories of an InfoPath 2010 installation:
Assembly |
Description |
---|---|
Microsoft.Office.InfoPath.dll |
The subset of the object model that contains only types and members that will run in the business logic of a form template deployed to a server that runs InfoPath Forms Services. |
Microsoft.Office.InfoPath.dll |
The "full" object model including types and members that will not run in the business logic of a form template deployed to InfoPath Forms Services. |
Note
The assemblies referenced earlier in this section are used at design time when you write and compile code. At run time, the assembly used when a form template is opened in InfoPath is located in the Global Assembly Cache (GAC) of the computer on which InfoPath is installed. When a form template is opened in a Web browser from a server that runs InfoPath Forms Services, the assembly used is located on the server.
Providing two assemblies helps ensure that your business logic will contain only calls to the appropriate object model members for the supported form editors (Web browser or InfoPath Filler). For example, when you edit your code, IntelliSense features such as statement completion and in-line documentation will only display and work against the appropriate object model members for your target form editors.
In both versions of the managed code object model exposed by the Microsoft.Office.InfoPath assembly, navigating and updating XML data stores in business logic requires calls to the members of the System.Xml.XPath.XPathNavigator class. In InfoPath 2003, navigating and updating XML data stores requires calling members of MSXML classes (for business logic created by using JScript or VBScript) or by calling through the wrappers for MSXML classes that are provided by the Microsoft.Office.Interop.InfoPath.SemiTrust namespace (for business logic created by using C# or Visual Basic and the Microsoft Office InfoPath 2003 Toolkit for Visual Studio .NET).
Using members of the XPathNavigator class allows the same business logic code to support DOM manipulation for form templates that are opened in both the InfoPath client and in Web-enabled forms opened from Microsoft SharePoint Server 2010 with InfoPath Forms Services in a Web browser.
For information about how to work with members of the XPathNavigator class in the business logic of InfoPath managed code form templates, see How to: Work with the XPathNavigator and XPathNodeIterator Classes.
The InfoPath 2003-Compatible Managed Code Object Model
The InfoPath 2003-compatible managed code object model was introduced in InfoPath 2003 Service Pack 1 together with the Microsoft Office InfoPath 2003 Toolkit for Visual Studio .NET for writing business logic in form templates with managed code. This object model is still supported by InfoPath 2010 to provide compatibility with InfoPath 2003.
The classes and members of this object model are exposed through the Microsoft.Office.Interop.InfoPath.SemiTrust namespace. This object model is implemented in the following assembly file which is located in the C:\Program Files\Microsoft Office\Office14 folder:
Assembly |
Description |
---|---|
Microsoft.Office.Interop.InfoPath.SemiTrust.dll |
Provides COM interop against the InfoPath COM object model for form template business logic written using C# or Visual Basic. |
Note
Although creating business logic with the COM interop managed-code object model provided by the Microsoft.Office.Interop.InfoPath.SemiTrust assembly is still supported by InfoPath 2010, business logic written using this object model it is not supported for browser-enabled form templates deployed to Microsoft SharePoint Server 2010 with InfoPath Forms Services. Browser-enabled form templates must use the InfoPath managed code object model for custom business logic.
Automating InfoPath from Managed Code
In addition to writing business logic with managed code, developers can automate InfoPath by using managed code running in an external application. This functionality and the assemblies required for writing code were introduced in InfoPath 2003 Service Pack 1. The objects and members for automating InfoPath have been updated to provide additional functionality when you write external automation code for InfoPath 2010.
The classes and members used for external automation are exposed through the Microsoft.Office.Interop.InfoPath and Microsoft.Office.Interop.InfoPath.Xml namespaces. The assembly files that are required for writing automation code are located in the C:\Program Files\Microsoft Office\Office14 folder:
Assembly |
Description |
---|---|
Microsoft.Office.Interop.InfoPath.dll |
Provides COM interop against the InfoPath COM object model for external automation code written using C# or Visual Basic. |
Microsoft.Office.Interop.InfoPath.Xml.dll |
Provides COM interop against the MSXML for XML DOM operations in external automation code written using C# or Visual Basic. |
For information about the object models provided by the Microsoft.Office.Interop.InfoPath and Microsoft.Office.Interop.InfoPath.Xml namespaces, which are used exclusively to automate the InfoPath application by using managed code from external applications, see the InfoPath Developer Center.
The InfoPath Forms Services Object Model
The managed code object model for automating InfoPath Forms Services administration tasks is implemented in the Microsoft.Office.InfoPath.Server.dll which is located at <drive>:\Program Files\Microsoft Office Server\14.0\Bin on a Microsoft SharePoint Server 2010 installation:
Assembly |
Description |
---|---|
Microsoft.Office.InfoPath.Server.dll |
The object model for automating InfoPath Forms Services tasks such as uploading, activating, or deactivating browser-enabled form templates. |
For more information about the InfoPath Forms Services object model, see the Microsoft SharePoint Server 2010 Software Developers Kit (SDK) which is available on MSDN.
InfoPath Development Environment
The development of business logic in InfoPath 2010 form templates can be performed by using the Microsoft Visual Studio Tools for Applications development environment.
Note
InfoPath 2010 does not support creating or editing form templates that use business logic written with JScript or VBScript, although the InfoPath Filler supports opening script-based form templates that were created in previous versions of InfoPath. Additionally, InfoPath 2010 does not support form template development in Visual Studio.
Visual Studio Tools for Applications
If your computer has Microsoft .NET Framework 2.0 or a later version installed, the Microsoft Visual Studio Tools for Applications development environment can be installed together with InfoPath 2010. If you did not have the Microsoft .NET Framework 2.0 or later version components installed when you first installed InfoPath, you must download and install those components before you can use the Microsoft Visual Studio Tools for Applications development environment.
The Microsoft Visual Studio Tools for Applications development environment is not installed by default when you install InfoPath. To install Microsoft Visual Studio Tools for Applications, you must either choose Customize when first installing, or use Add or Remove Features to update your Office or InfoPath installation to include Microsoft Visual Studio Tools for Applications. The option to install Microsoft Visual Studio Tools for Applications is available by expanding Microsoft Office InfoPath and .NET Programmability Support in the setup program.
The Microsoft Visual Studio Tools for Applications environment can be used to write business logic in C# or Visual Basic against either the InfoPath 2003-compatible object model (members of the Microsoft.Office.Interop.InfoPath.SemiTrust namespace) or the new managed code object model (members of the Microsoft.Office.InfoPath namespace).
Maintaining, Creating, and Converting Form Templates That Work with the InfoPath 2003 Object Model
Microsoft Visual Studio Tools for Applications lets you open and continue to work on InfoPath form template projects created by using the Microsoft Office InfoPath 2003 Toolkit for Visual Studio .NET or with Visual Studio 2005 Tools for the Microsoft Office System.
Note
Users of form templates compiled with Microsoft Visual Studio Tools for Applications must have Microsoft .NET Framework 2.0 or a later version installed on their computers. Whereas users of form templates compiled with Visual Studio .NET 2003 only require Microsoft .NET Framework 1.1 on their computers.
To use Microsoft Visual Studio Tools for Applications and maintain backward compatibility with InfoPath 2003, create a new form template, click Language on the Developer tab, click Compatibility, and then the Form type to InfoPath 2003 Filler Form. Then click Programming, and set the Form template code language to the language that you want to use.
Additionally, you can convert a form template that works with the InfoPath 2003 object model to use the new InfoPath managed code object model. For information about how to convert form templates, see How to: Open or Convert a Form Template Created with the InfoPath Toolkit.
See Also
Tasks
Walkthrough: Creating a Basic Form Template with Code
Walkthrough: Creating and Debugging a Basic Form Template Using the InfoPath 2003 Object Model