Share via


How to: Add and Reference Custom Assemblies Using the InfoPath 2003 Object Model

When you add a reference to a custom assembly in a managed-code form template project, that assembly is included within the form template file (.xsn) when your project is compiled and published.

Add and Reference a Custom Assembly

To avoid a conflict with how the InfoPath project system manages files that are added to the form template file, do not copy any custom assemblies that you want to reference into the top-level folder of a form template project. By default, this will be a path in the following format: <drive>:\Documents and Settings\UserName\My Documents\Visual Studio Projects\ProjectName

If you do want to move custom assemblies that you reference within the project folder, you must create a subfolder below the main project folder and copy and reference custom assemblies from that subfolder. However, note that creating a subfolder for referenced assemblies is not necessary. As long as a referenced assembly is not located within the project's top-level folder, the InfoPath project system will copy the assembly into the form template file (.xsn) when the project is compiled and published.

Reference a custom assembly from its default location

  1. Open the form template project in Microsoft Visual Studio Tools for Applications (VSTA), Visual Studio 2005 with Microsoft Visual Studio 2005 Tools for the 2007 Microsoft Office System, or Visual Studio 2008 with Visual Studio Tools for Office.

  2. On the Project menu, click Add Reference.

  3. On the .NET tab, click Browse, locate the assembly, and then click OK to add the reference.

Dependencies in Referenced Subprojects (Visual Studio)

In Visual Studio, if you add and reference an additional project, such as a Class Library, as a subproject to an InfoPath managed-code form template solution (by pointing to New on the File menu, clicking Project, and selecting Add to Solution in the New Project dialog box, and then adding the subproject as a reference in the InfoPath project), any assemblies referenced by the subproject will not be included in the project’s form template file (projectname.xsn) and the resulting form will not load correctly. To work around this problem, edit the form definition file (manifest.xsf) and manually add entries for the assemblies referenced by the subproject using the following procedure.

Add dependent assemblies from referenced subprojects

  1. Close the InfoPath form design window.

  2. In Solution Explorer, right-click manifest.xsf, and then click Open.

  3. Within the <xsf:files> element, add an XML fragment in the following format for each component that the subproject references, replacing AssemblyName.dll with the actual name of the referenced component:

    <xsf:file name="AssemblyName.dll">
        <xsf:fileProperties>
            <xsf:property name="fileType" type="string" value="refAssembly"></xsf:property>
            </xsf:fileProperties>
    </xsf:file>
    
  4. Save your changes to the manifest.xsf file.

  5. After manually updating the manifest.xsf file, copy each component referenced by the subproject (AssemblyName.dll) to the folder where the manifest.xsf file is located. Typically this will be a path within your My Documents folder in this format: <drive>:\Documents and Settings\UserName\My Documents\Visual Studio Projects\ProjectName\. When you compile and publish the form template file, it will include the output of the subproject and the assemblies referenced by the subproject.

See Also

Tasks

How to: Create a Managed Code Form Template Using the InfoPath 2003 Object Model