I have a SDE featureclass that is joined to an access table in my map control. I want to export selected features of the SDE layer to a shapefile AND retain the joined fields. this following method works great (except for retaining the joined fields)
public void ExportMapLyrToShapefile(ESRI.ArcGIS.Carto.ILayer pInLayer, string inputName, string outputPath, string qry)
{
// Set the GeoFeatureLayer to the layer in the map so that we can use it as the input feature later
IGeoFeatureLayer pInGFLayer = (IGeoFeatureLayer)pInLayer;
IFeatureLayer pInFeatureLayer = (IFeatureLayer)pInGFLayer;
IFeatureClass inputFeatureClass = pInFeatureLayer.FeatureClass;
IDataset inputDataset = (IDataset)inputFeatureClass;
IDatasetName inputDatasetName = (IDatasetName)inputDataset.FullName;
// Get the layer's selection set (the selected/highlighted features of the layer in the mapcontrol)
IFeatureSelection featureSelection = (IFeatureSelection)pInFeatureLayer;
ISelectionSet selectionSet = featureSelection.SelectionSet;
// Create a feature class name for the output shapefile and open the output's workspace
IWorkspaceFactory shpWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
IWorkspace shpWorkspace = shpWorkspaceFactory.OpenFromFile(outputPath, 0);
IDataset shpWorkspaceDataset = (IDataset)shpWorkspace;
IWorkspaceName workspaceName = (IWorkspaceName)shpWorkspaceDataset.FullName;
IFeatureClassName shpFeatureClassName = new FeatureClassNameClass();
IDatasetName shpDatasetName = (IDatasetName)shpFeatureClassName;
shpDatasetName.WorkspaceName = workspaceName;
shpDatasetName.Name = qry.Replace(" = ", "");
// Use the IFieldChecker interface to make sure all of the field names are valid for the output shapefile.
IFieldChecker fieldChecker = new FieldCheckerClass();
IFields shapefileFields = null;
IEnumFieldError enumFieldError = null;
fieldChecker.InputWorkspace = inputDataset.Workspace;
fieldChecker.ValidateWorkspace = shpWorkspace;
fieldChecker.Validate(inputFeatureClass.Fields, out enumFieldError, out shapefileFields);
// We also need to retrieve the GeometryDef from the input feature class.
int shapeFieldPosition = inputFeatureClass.FindField(inputFeatureClass.ShapeFieldName);
IFields inputFields = inputFeatureClass.Fields;
IField shapeField = inputFields.get_Field(shapeFieldPosition);
IGeometryDef geometryDef = shapeField.GeometryDef;
// Now we create a feature data converter to "Export" the selected features to a shapefile
IFeatureDataConverter2 featureDataConverter2 = new FeatureDataConverterClass();
IEnumInvalidObject enumInvalidObject = featureDataConverter2.ConvertFeatureClass(inputDatasetName, null, selectionSet, null, shpFeatureClassName, geometryDef, shapefileFields, "", 1000, 0);
}
the issue is with the IFieldChecker interface. it validates all the fields and removed the joined fields before exporting to a shapefile.
Does anyone have any insight on this issue? If so, please help! I'm stumpped!
btw... i also tried using an IDisplayTable as my input feature and I get the same output (missing joined fields)
Thanks, Derek