I am stuck for couple of days trying to figure out this how to field map from shapefile into personal geodatabase using c#.NET. I want to use ESRI.ArcGIS.DataManagementTools.Append tool in geoprocessing to do this. Filed "Product" in shapefile needs to be transferred to field "OriginalProduct" in the geodatabase. Following is my code. Please help me out.
static void Main(string[] args)
{
// GET INPUT SHAPEFILE
string m_shapefileName = @"F:\PhD\LULCM\ReprocessingTashigang\TestGewogFolder\TestArcobj\ExportShapefiles\ForestsA.shp";
string fileName = System.IO.Path.GetFileNameWithoutExtension(m_shapefileName);
//instantiate a new workspace factory
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
//get the workspace directory
string path = System.IO.Path.GetDirectoryName(m_shapefileName);
//open the workspace containing the featureclass
IFeatureWorkspace featureWorkspace = workspaceFactory.OpenFromFile(path, 0) as IFeatureWorkspace;
//open the featureclass
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(fileName);
Geoprocessor gp = new Geoprocessor();
//IVariantArray parameters = new VarArrayClass();
Append appendTool = new Append();
IGPUtilities gputilities = new GPUtilitiesClass();
//"F:\\PhD\\LULCM\\ReprocessingTashigang\\TestGewogFolder\\TestArcobj\\ExportShapefiles\\ForestsA.shp"
IDETable inTableA = (IDETable)gputilities.MakeDataElement("F:\\PhD\\LULCM\\ReprocessingTashigang\\TestGewogFolder\\TestArcobj\\ExportShapefiles\\ForestsA.shp", null, null);
//create an input or array tables
IArray inTables = new ArrayClass();
//inTables.Add(inTableA);
//IArray inTableBB = new ArrayClass();
inTables.Add(inTableA);
// Initialize the GPFieldMapping
IGPFieldMapping fieldmapping = new GPFieldMappingClass();
fieldmapping.Initialize(inTables, null);
// Create a new output field
IFieldEdit trackidfield = new FieldClass();
trackidfield.Name_2 = "OriginalProduct";
trackidfield.Type_2 = esriFieldType.esriFieldTypeInteger;
//trackidfield.Length_2 = 50;
// Create a new FieldMap
IGPFieldMap trackid = new GPFieldMapClass();
trackid.OutputField = trackidfield;
// Find field map "OriginalProduct" containing the input field "Product". Add input field to the new field map.
int fieldmap_index = fieldmapping.FindFieldMap("Product");
IGPFieldMap stfid_fieldmap = fieldmapping.GetFieldMap(fieldmap_index);
int field_index = stfid_fieldmap.FindInputField(inTableA, "Product");
IField inputField = stfid_fieldmap.GetField(field_index);
trackid.AddInputField(inTableA, inputField,0,0);
// Add the new field map to the field mapping
fieldmapping.AddFieldMap(trackid);
//trackid.AddInputField(inTableA, inputField, 5, 10);
// Find field map "Product" containing the input field "Product". Add input field to the new field map.
/*int fieldmap_index1 = fieldmapping.FindFieldMap("Product");
IGPFieldMap stfid_fieldmap1 = fieldmapping.GetFieldMap(fieldmap_index1);
int field_index1 = stfid_fieldmap1.FindInputField(inTableA, "Product");
IField inputField1 = stfid_fieldmap1.GetField(field_index1);*/
// Create a new FieldMap
//IGPFieldMap trackid1 = new GPFieldMapClass();
//trackid.OutputField = trackidfield;
appendTool.inputs = featureClass;
appendTool.target = @"F:\PhD\LULCM\ReprocessingTashigang\TestGewogFolder\TestArcobj\Empty_Gewog_PGDB.mdb\Landcover\ForestA"; // target file
appendTool.schema_type = "NO_TEST";
appendTool.field_mapping = fieldmapping;
appendTool.subtype = ""; // join_field
gp.Execute(appendTool, null);
Console.ReadLine();
}