This documentation is archived and is not being maintained.

IInfoPathDataImporter.Import Method

Office 2007
Imports data into the current form.

Version Information
 Version Added:  InfoPath 2007


expression.Import(pPrintSettings, punkViewControls)

expression   An expression that returns an IInfoPathDataImporter interface.


NameRequired/OptionalData TypeDescription
pPrintSettingsRequiredIPropertyBagA collection of print settings.
punkViewControlsRequired[IENUMUNKNOWN]An mshtml.IEnumUnknown collection of controls in the view.

Return Value


The following print settings are available through the IPropertyBag interface.

Print ValueDescription
PageSizeThe current page size, such as A4, B4, Letter.
TopMarginThe top margin of the current view.
BottomMarginThe bottom margin of the current view.
LeftMarginThe left margin of the current view.
RightMarginThe right margin of the current view.
MarginUnitsTypeThe margin measurement units.

This object or member is used for extending the InfoPath application and is not intended to be used directly from your form code.

For more information about programmatically importing data into an InfoPath form, see the InfoPath Developer Portal on the Microsoft Office Developer Center.


In the following example, the Import method of the IInfoPathDataImporter interface is used to iterate through the mshtml.IEnumUnknown collection of IInfoPathViewControl controls in the view of the active form.

The Import routine is the main part of a solution used to build a custom data importer. The Visual Studio project requires a reference to the Microsoft Office InfoPath 2.0 Type Library and System.Windows.Forms, with Imports statements for each as well as mshtml. Implements statements are required to generate the signatures for the methods provided by the custom data importer interfaces, including IInfoPathDataImporter, IInfoPathDataImporterFields, IInfoPathViewControl, and IPropertyBag.

Bb250952.vs_note(en-us,office.12).gif  Note
To build a custom data importer using a .NET class library, check the Register for COM interop check box on the Compile tab of the class properties editor.
Bb250952.vs_note(en-us,office.12).gif  Note
To debug a custom data importer, set a Start Action in Visual Studio to Start an external program, and browse to INFOPATH.EXE located at <drive>:\Program Files\Microsoft Office\Office12\. This option is available on the Debug tab of the class properties editor.
Visual Basic
Imports Microsoft.Office.Interop.InfoPath
Imports System.Windows.Forms
Imports mshtml

<ComClass(Class1.ClassId, Class1.InterfaceId, Class1.EventsId)> Public Class Class1
    Implements Microsoft.Office.Interop.InfoPath.IInfoPathDataImporter
    Implements Microsoft.Office.Interop.InfoPath.IInfoPathDataImporterFields
    Implements Microsoft.Office.Interop.InfoPath.IInfoPathViewControl
    Implements Microsoft.Office.Interop.InfoPath.IPropertyBag

    Public Const ClassId As String = "1FEB0DF8-E7F1-4b21-A9EE-B06D5FECC572"
    Public Const InterfaceId As String = "9F9F685C-71A0-46ec-A7F9-A86AF8CBC2A8"
    Public Const EventsId As String = "ED7C0C49-3F89-40a2-A50E-C59E8F682B08" 

Public Sub Import(ByVal pPrintSettings As Microsoft.Office.Interop.InfoPath.IPropertyBag, ByVal punkViewControls As mshtml.IEnumUnknown) Implements Microsoft.Office.Interop.InfoPath.IInfoPathDataImporter.Import

    Dim pControl As IInfoPathViewControl    
    Dim pUnk As Object
    Dim pcelt As UInt16 = 1
    Dim pceltFetched As UInt16 = 0

        'Gets first control in the view
        punkViewControls.RemoteNext(pcelt, pUnk, pceltFetched)

        Do While pUnk.ToString() <> "Nothing"
            pControl = pUnk
            'Gets next control in the view
            punkViewControls.RemoteNext(pcelt, pUnk, pceltFetched)
    Catch e As Exception
        If e.Message = "Object reference not set to an instance of an object." Then
            'Signals the end of the enumeration/controls in the view
            MessageBox.Show("Error: " & e.ToString & " " & e.Message)
        End If
    End Try
End Sub