public static void ExportLayerToShapefile(string shapePath, string shapeName, ILayer source) { try { // cast the selected/requested layer into a feature layer ESRI.ArcGIS.Carto.IFeatureLayer featureLayer = (IFeatureLayer)source; // create a new feature class to feature class converter utility ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass fc2fc = new ESRI.ArcGIS.ConversionTools.FeatureClassToFeatureClass(); // set the input feature layer fc2fc.in_features = featureLayer; // set the output path and Shapefile name fc2fc.out_path = shapePath; fc2fc.out_name = shapeName + ".shp"; // create a new GeoProcessor ESRI.ArcGIS.Geoprocessor.Geoprocessor geoprocessor = new ESRI.ArcGIS.Geoprocessor.Geoprocessor(); geoprocessor.TemporaryMapLayers = true; // execute the FeatureClassToFeatureClass geoprocessor.Execute(fc2fc, null); // export a copy of the layer file definition too for upload/style at a later time ESRI.ArcGIS.DataManagementTools.SaveToLayerFile saveToLayerFile = new ESRI.ArcGIS.DataManagementTools.SaveToLayerFile(); saveToLayerFile.in_layer = source; saveToLayerFile.out_layer = shapePath + "\\" + shapeName + ".lyr"; // execute the FeatureClassToFeatureClass geoprocessor.Execute(saveToLayerFile, null); // remove reference to the tool and geoprocessor fc2fc = null; geoprocessor = null; } catch (Exception ex) { // an error occured System.Windows.Forms.MessageBox.Show("Error: " + ex.Message); } }