I will chime in on this since i've been struggling to figure this out too... here's what i had to do.... (ArcEngine application)1) select the features in the layer that you want in your map control
/// <summary>
/// selects a feature from a specific featureclass
/// </summary>
/// <param name="myMap">map control</param>
/// <param name="player">layer to search on in the map control</param>
/// <param name="searchString">search criteria</param>
public void selectFeature(AxMapControl myMap, ILayer player, string searchString)
{
pFeatureLayer = (IFeatureLayer)player;
if (pFeatureLayer != null)
{
//select the feature
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = searchString;
IFeatureSelection featureSelection = (IFeatureSelection)pFeatureLayer;
myMap.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, pFeatureLayer, null);
featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
}
return;
}
2) then call the code to run the "Export"
/// <summary>
/// Exports the selected features of a layer in the Map Control to a Shapefile
/// </summary>
/// <param name="pLayer">mapcontrol layer</param>
/// <param name="inputPath">input shapefile full path</param>
/// <param name="outputPath">output shapefile full path</param>
/// <param name="qry">query to filter out features</param>
public void ExportMapLyrToShapefile(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;
//// Create a query filter to select specific features in the input featureclass
//IQueryFilter queryFilter = new QueryFilterClass();
//queryFilter.WhereClause = qry;
// 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);
}
*note that i didn't use the IQueryFilter.... I kept getting errors when going that route...Now, the only issue i'm running into is that I have a table joined to the map layer and those joined fields are not being "exported"! So far no luck on this particular issue.If anyone has any info on how I can include my joined table's fields in the "Export"... please help!Derek