Overview of the InfoPath Designer API for Integrating InfoPath 2007 into Visual Studio 2005

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

Summary: Learn about how the Microsoft Office InfoPath 2007 form template design environment is integrated into the Visual Studio 2005 IDE when Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System is installed. This article also describes the VsInfoPathDesigner object and the nine functions that InfoPath provides to perform project-related tasks when the InfoPath design environment is hosted as a custom editor in Visual Studio. (9 printed pages)

Mark Roberts, Microsoft

Gary Hsu, Microsoft

October, 2006

Applies to: Microsoft 2007 Office Suites, Microsoft Office InfoPath 2007, Microsoft Visual Studio 2005

Contents

  • Overview of InfoPath 2007 Integration in Visual Studio

  • InfoPath Designer API for Integrating InfoPath 2007 into Visual Studio

  • Conclusion

  • Additional Resources

Overview of InfoPath 2007 Integration in Visual Studio

When you are using Visual Studio 2005 Tools for the 2007 Microsoft Office system, the Microsoft Office InfoPath 2007 form template design environment is integrated into the Microsoft Visual Studio 2005 development environment. In this integrated environment, you can use the features of Office InfoPath 2007 to design the layout of InfoPath form templates and write managed code business logic without leaving Visual Studio. When working with InfoPath form templates in Visual Studio, a developer writes business logic in C# or Microsoft Visual Basic against either the new Office InfoPath 2007 managed code object model (types and members of the Microsoft.Office.InfoPath namespace) or the Microsoft Office InfoPath 2003–compatible object model (types and members of the Microsoft.Office.Interop.InfoPath.SemiTrust namespace).

After installing the Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System, you can create a custom Visual Studio project type (an InfoPath Form Template for C# or Visual Basic), and then use the InfoPath 2007 form template design environment, which is hosted as a custom Visual Studio editor, for form template design tasks as well as adding event handlers and other business logic code.

The InfoPath 2007 form template design environment is integrated into the Visual Studio integrated development environment (IDE) by installing and registering a VSPackage that was created using the process described in the Visual Studio Integration section of the Visual Studio SDK. VSPackages are software modules that make up and extend the Visual Studio IDE by providing user interface elements, services, projects, editors, and designers. The InfoPath Designer VSPackage acts as a wrapper for integrating the InfoPath design environment's user interface elements and functionality into Visual Studio. The VSPackage depends on a local installation of InfoPath 2007 to work properly.

The InfoPath Designer VSPackage is registered as Visual Studio 2005 Editor package in the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Editors\{6ab7a76b-2809-4a7c-bff6-2a3b99feef91}

The kind of project created by an InfoPath Form Template project is a Visual Studio Tools for Applications (VSTA) project, and includes dependencies on VSTA components that are installed with InfoPath 2007.

To get the most current information about Visual Studio Integration, including sample solutions and tools, download the Visual Studio SDK. To do that, register or log on as a Visual Studio Industry Partner (VSIP) affiliate member on the Development Tools Ecosystem Partner Portal, and then download the Visual Studio SDK. For more information about Visual Studio integration, see the Visual Studio Extensibility Forum on MSDN and the Discussions in Extensibility newsgroup.

Information about VSTA will eventually be included in the Visual Studio SDK, but at the time of publication of this article, this information is not available in the SDK. For current information about VSTA, see the Additional Resources section at the end of the article.

InfoPath Designer API for Integrating InfoPath 2007 into Visual Studio

The InfoPath designer object, VsInfoPathDesigner, is implemented in the IPDESIGN.dll that is installed in the drive:\Program Files\Microsoft Office\OFFICE12 directory when InfoPath 2007 is installed. The VsInfoPathDesigner object implements the required interfaces for integrating the InfoPath design environment with Visual Studio. The IPDESIGN.dll component also provides nine functions that are used to perform InfoPath project-related tasks when the InfoPath design environment is hosted as a custom editor in Visual Studio 2005. The VsInfoPathDesigner object implements the IVsWindowFrame interface to host InfoPath document and tool windows in Visual Studio. See the Basic Edit Sample and Figures Edit Sample in the Visual Studio SDK for examples of integrating a custom editor into Visual Studio.

The Class ID (CLSID) for the VsInfoPathDesigner object is {6ab7a76b-2809-4a7c-bff6-2a3b99feef91}.

The following code shows the declaration of the CLSID of the VsInfoPathDesigner object.

extern "C" const __declspec(selectany) CLSID CLSID_VsInfoPathDesigner =
   { 0x6AB7A76B, 0x2809, 0x4A7C, 
   { 0xBF, 0xF6, 0x2A, 0x3B, 0x99, 0xFE, 0xEF, 0x91 } };

The IPDESIGN.dll exports the following nine functions:

  • RunVsTemplateWizard

  • RunPostVsProjectCreationTasks

  • ConvertInfoPathProjectForVSTO

  • GetAssociatedVsDocument

  • CreateVsWorkpane

  • CanShowVsWorkpane

  • ExecVsExportTemplate

  • RunStartupTasksForVSTO

  • ResetToolboxItems

The following sections describe each of these functions.

RunVsTemplateWizard

RunVsTemplateWizard launches the Design a Form Template dialog box.

STDAPI RunVsTemplateWizard(
      IN    BSTR                    bstrManifestPath,
      IN    BSTR                    bstrProjectName,
      IN    BSTR                    bstrProjectPath,
      IN    BSTR                    bstrLanguage,
      OUT   InfoPathDesignMode*     peDesignMode,
      OUT   BOOL*                   pfO12OM,
      OUT   BOOL*                   pfAllowClientOnlyCode);

Table 1 describes the parameters of the RunVsTemplateWizard function.

Table 1. Parameters of the RunVsTemplateWizard function

Parameter

Definition

bstrManifestPath

Specifies the location where the solution will be saved.

bstrProjectName

Specifies the name of the project that is used for the solution caption.

bstrProjectPath

Specifies the path to the project file (corresponds to the managedCode/@projectPath attribute in the form template's manifest.xsf file).

bstrLanguage

Specifies the programming language for the form template project. Can be either CSharp or VisualBasic (corresponds to the managedCode/@language attribute in the form template's manifest.xsf file).

peDesignMode

Returns a value that indicates the design mode of the project. This corresponds to the setting of the Enable browser-compatible features only check box in the Design a Form Template dialog box. Returns 1 if the check box is not selected; returns 2 if the check box is selected.

pfO12OM

Returns a value that indicates which InfoPath managed code object model is referenced. Returns TRUE if the Microsoft.Office.InfoPath assembly is referenced; returns FALSE if the Microsoft.Office.Interop.InfoPath.SemiTrust assembly is referenced.

pfAllowClientOnlyCode

Returns a value that indicates whether the Hide errors for code that uses InfoPath-only features check box is selected in the Compatibility category of the Form Options dialog box. Returns TRUE if the check box is selected; returns FALSE if the check box is not selected.

When the user creates or loads a form template from the Design a Form Template dialog box, the designer will always save a new copy of the solution that the user picked.

RunPostVsProjectCreationTasks

RunPostVsProjectCreationTasks runs tasks after the project has been created, such as validating the assembly name, initializing code files, updating references, and creating the signing key.

STDAPI RunPostVsProjectCreationTasks(
      IN    IDispatch*              pdispProject,
      IN    BOOL                    fO12OM,
      IN    BOOL                    fCSharp,
      IN    InfoPathDesignMode      eDesignMode,
      IN    BOOL                    fEnableClientOnlyCode);

Table 2 describes the parameters of the RunPostVsProjectCreationTasks function.

Table 2. Parameters of the RunPostVsProjectCreationTasks function

Parameter

Definition

pdispProject

Specifies the IDispatch pointer to the project object.

fO12OM

Specifies which InfoPath managed code object model to reference:

  • Microsoft.Office.InfoPath assembly

  • Microsoft.Office.Interop.InfoPath.SemiTrust assembly

Specify TRUE to reference the object model provided by the Microsoft.Office.InfoPath assembly; specify FALSE to reference the object model provided by the Microsoft.Office.Interop.InfoPath.SemiTrust assembly.

fCSharp

Specifies which programming language to use for the project. Specify TRUE to use C#; specify FALSE to use Visual Basic.

eDesignMode

Specifies the design mode for the project. This corresponds to the setting of the Enable browser-compatible features only check box in the Design a Form Template dialog box. Specify 1 if the check box is not selected; specify 2 if the check box is selected.

fEnableClientOnlyCode

Specifies whether to enable client-only code. This corresponds to whether the Hide errors for code that uses InfoPath-only features check box is selected in the Compatibility category of the Form Options dialog box. Specify TRUE if the check box is selected; specify FALSE if the check box is not selected.

ConvertInfoPathProjectForVSTO

ConvertInfoPathProjectForVSTO converts an InfoPath managed code form template project created using one of the InfoPath 2003 Toolkits to a Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System (VSTO) project.

STDAPI ConvertInfoPathProjectForVSTO(
      IN    BSTR                    bstrProjectLocation,
      IN    IServiceProvider*       pServiceProvider,
      OUT   BSTR*                   pbstrNewProjectLocation,
      OUT   GUID*                   pguidNewProjectFactory,
      OUT   BOOL*                   pfWhidbeySolution);

Table 3 describes the parameters of the ConvertInfoPathProjectForVSTO function.

Table 3. Parameters of the ConvertInfoPathProjectForVSTO function

Parameter

Definition

bstrProjectLocation

Specifies the location of the project.

pServiceProvider

Specifies the IServiceProvider pointer to the service provider from Visual Studio.

pbstrNewProjectLocation

Returns the new project location.

pguidNewProjectFactory

Returns the GUID of the new project factory (either the C# project GUID or the Visual Basic project GUID).

pfWhidbeySolution

Returns whether the original project was created with the InfoPath 2003 Toolkit for Visual Studio .NET 2003 or with the Microsoft Visual Studio 2005 Tools for the Microsoft Office System. Returns TRUE if the original project was a Microsoft Visual Studio 2005 Tools for the Microsoft Office System project; returns FALSE if the original project was an InfoPath 2003 Toolkit for Visual Studio .NET 2003 project.

GetAssociatedVsDocument

GetAssociatedVsDocument gets the current active document that is associated with the InfoPath designer.

STDAPI GetAssociatedVsDocument(
      OUT   IUnknown**              ppunkAssociatedVsDocument);

Table 4 describes the parameters of the GetAssociatedVsDocument function.

Table 4. Parameters of the GetAssociatedVsDocument function

Parameter

Definition

ppunkAssociatedVsDocument

Returns the IUnknown pointer to the document.

CreateVsWorkpane

CreateVsWorkpane creates an InfoPath task pane tool window.

STDAPI CreateVsWorkpane(
      IN    IUnknown*        punkSite,
      IN    REFGUID          rguidPersistenceGuid
      OUT   IVsWindowFrame** ppWindowFrame);

Table 5 describes the parameters of the CreateVsWorkpane function.

Table 5. Parameters of the CreateVsWorkpane function

Parameter

Definition

punkSite

Specifies the IUnknown pointer to the service provider from Visual Studio.

rguidPersistenceGuid

Specifies the GUID of the InfoPath task pane to create.

ppWindowFrame

Returns a IVsWindowFrame pointer to the Visual Studio tool window that contains the specified task pane.

Use the GUID values shown in Table 6 to specify the value of the rguidPersistenceGuid parameter.

Table 6. GUID values for the rguidPersistenceGuid parameter

Task pane

GUID

Asian Typography

{00000716-2809-4A7C-BFF6-2A3B99FEEF91}

Bullets and Numbering

{00000725-2809-4A7C-BFF6-2A3B99FEEF91}

Color Schemes

{000005E5-2809-4A7C-BFF6-2A3B99FEEF91}

Data Source

{00000724-2809-4A7C-BFF6-2A3B99FEEF91}

Design Checker

{00000855-2809-4A7C-BFF6-2A3B99FEEF91}

Design Tasks

{000007BD-2809-4A7C-BFF6-2A3B99FEEF91}

Font

{000007B8-2809-4A7C-BFF6-2A3B99FEEF91}

Grid

{00000717-2809-4A7C-BFF6-2A3B99FEEF91}

Layout

{00000768-2809-4A7C-BFF6-2A3B99FEEF91}

Paragraph

{000005AA-2809-4A7C-BFF6-2A3B99FEEF91}

Spelling

{000006DA-2809-4A7C-BFF6-2A3B99FEEF91}

Views

{000006DC-2809-4A7C-BFF6-2A3B99FEEF91}

NoteNote

The Asian Typography and Grid task panes are available only in Asian language versions of InfoPath 2007.

CanShowVsWorkpane

CanShowVsWorkpane determines if the specified InfoPath task pane can be displayed.

STDAPI CanShowVsWorkpane(
      IN    IUnknown*               punkSite,
      IN    REFGUID                 rguidPersistenceGuid,
      OUT   BOOL*                   pfCanShow);

Table 7 describes the parameters of the CanShowVsWorkpane function.

Table 7. Parameters of the CanShowVsWorkpane function

Parameter

Definition

punkSite

Specifies the IUnknown pointer to the service provider from Visual Studio.

rguidPersistenceGuid

Specifies the GUID associated with the InfoPath task pane.

pfCanShow

Returns TRUE if the task pane can be shown; otherwise returns FALSE.

Use the GUID values shown in Table 8 to specify the value of the rguidPersistenceGuid parameter.

Table 8. GUID values for the rguidPersistenceGuid parameter

Task pane

GUID

Asian Typography

{00000716-2809-4A7C-BFF6-2A3B99FEEF91}

Bullets and Numbering

{00000725-2809-4A7C-BFF6-2A3B99FEEF91}

Color Schemes

{000005E5-2809-4A7C-BFF6-2A3B99FEEF91}

Data Source

{00000724-2809-4A7C-BFF6-2A3B99FEEF91}

Design Checker

{00000855-2809-4A7C-BFF6-2A3B99FEEF91}

Design Tasks

{000007BD-2809-4A7C-BFF6-2A3B99FEEF91}

Font

{000007B8-2809-4A7C-BFF6-2A3B99FEEF91}

Grid

{00000717-2809-4A7C-BFF6-2A3B99FEEF91}

Layout

{00000768-2809-4A7C-BFF6-2A3B99FEEF91}

Paragraph

{000005AA-2809-4A7C-BFF6-2A3B99FEEF91}

Spelling

{000006DA-2809-4A7C-BFF6-2A3B99FEEF91}

Views

{000006DC-2809-4A7C-BFF6-2A3B99FEEF91}

NoteNote

The Asian Typography and Grid task panes are only available in Asian language versions of InfoPath 2007.

ExecVsExportTemplate

ExecVsExportTemplate displays a warning if an InfoPath designer is currently active. It returns S_OK if the warning was shown, otherwise it returns OLECMDERR_E_UNKNOWNGROUP.

STDAPI ExecVsExportTemplate(
      IN    IUnknown*               punkSite);

Table 9 describes the parameters of the ExecVsExportTemplate function.

Table 9. Parameters of the ExecVsExportTemplate function

Parameter

Definition

punkSite

Specifies the IUnknown pointer to the service provider from Visual Studio.

RunStartupTasksForVSTO

RunStartupTasksForVSTO runs VSTA-specific startup tasks when the project has loaded.

STDAPI RunStartupTasksForVSTO(
      IN    IDispatch*              pdispHostAdapter);

Table 10 describes the parameters of the RunStartupTasksForVSTO function.

Table 10. Parameters of the RunStartupTasksForVSTO function

Parameter

Definition

pdispHostAdapter

Specifies the IDispatch pointer to the IVstaHostAdapter interface pointer.

ResetToolboxItems

ResetToolboxItems resets the InfoPath items in the Visual Studio Toolbox.

STDAPI ResetToolboxItems();

Conclusion

Installing Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System provides the InfoPath Form Template custom project type, and integrates the Office InfoPath 2007 form template design environment into the Visual Studio 2005 development environment as a custom editor using Visual Studio Integration, as documented in the Visual Studio SDK. InfoPath 2007 provides nine methods that can be called by the Visual Studio environment to perform various InfoPath form template project–related tasks.

Additional Resources

For more information about developing with InfoPath, see the InfoPath Developer Portal.

For more information about VSTA, see: