Geoprocessing field mapping
GPFieldMapping\FieldMapping.vb
' Copyright 2010 ESRI
' 
' All rights reserved under the copyright laws of the United States
' and applicable international laws, treaties, and conventions.
' 
' You may freely redistribute and use this sample code, with or
' without modification, provided you include the original copyright
' notice and use restrictions.
' 
' See the use restrictions.
' 

Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Geoprocessing
Imports ESRI.ArcGIS.Geoprocessor
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.ConversionTools

Namespace GPFieldMapping
  Friend Class FieldMapping
    Shared Sub Main(ByVal args As String())
            ' Initialize license
            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop)

            Dim aoi As IAoInitialize = New AoInitializeClass()
            aoi.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcInfo)

            ' Initialize the Geoprocessor
            Dim GP As ESRI.ArcGIS.Geoprocessor.Geoprocessor = New ESRI.ArcGIS.Geoprocessor.Geoprocessor()

      ' Create the GPUtilites object
      Dim gputilities As IGPUtilities = New GPUtilitiesClass()

      ' Create a DETable data element object 
            Dim inputTableA As IDETable = CType(gputilities.MakeDataElement("C:\gp\citiblocks.gdb\census", Nothing, Nothing), IDETable) 

      ' Create an array of input tables
      Dim inputtables As IArray = New ArrayClass()
      inputtables.Add(inputTableA)

            ' Initialize the GPFieldMapping
      Dim fieldmapping As IGPFieldMapping = New GPFieldMappingClass()
      fieldmapping.Initialize(inputtables, Nothing)

      ' Create a new output field
      Dim trackidfield As IFieldEdit = New FieldClass()
      trackidfield.Name_2 = "TRACTID"
      trackidfield.Type_2 = esriFieldType.esriFieldTypeString
      trackidfield.Length_2 = 50

      ' Create a new FieldMap
      Dim trackid As IGPFieldMap = New GPFieldMapClass()
      trackid.OutputField = trackidfield

      ' Find field map "STFID" containing the input field "STFID". Add input field to the new field map.
      Dim fieldmap_index As Integer = fieldmapping.FindFieldMap("STFID")
      Dim stfid_fieldmap As IGPFieldMap = fieldmapping.GetFieldMap(fieldmap_index)
      Dim field_index As Integer = stfid_fieldmap.FindInputField(inputTableA, "STFID")
      Dim inputField As IField = stfid_fieldmap.GetField(field_index)
      trackid.AddInputField(inputTableA, inputField, 5, 10)

      ' Add the new field map to the field mapping
      fieldmapping.AddFieldMap(trackid)

      ' Execute Table to Table tool using the FieldMapping
      Dim tblTotbl As TableToTable = New TableToTable()
      tblTotbl.in_rows = inputTableA
            tblTotbl.out_path = "C:\gp\citiblocks.gdb" 
            tblTotbl.out_name = "CensusVistaVB"
      tblTotbl.field_mapping = fieldmapping

      GP.Execute(tblTotbl, Nothing)
    End Sub
  End Class
End Namespace