I read the post of a hero and wrote something similar to this one. So I copied it directly and made a class in. You can use it directly.
Using System;
Using System. Collections. Generic;
Using System. Text;
Using ESRI. ArcGIS. Geodatabase;
Using System. Windows. Forms;
Using ESRI. ArcGIS. DataSourcesFile;
Namespace topo.com
{
/// <Summary>
/// After the buffer analysis is exported, the point layer of JointCount> 1 appears.
/// </Summary>
Public class ExportToShp
{
Public string shpPath;
/// <Summary>
/// Save the point layer that outputs JointCount> 1
/// </Summary>
/// <Param name = "apFeatureClass"> </param>
Public void ExportFeatureClassToShp (IFeatureClass apFeatureClass)
{
If (apFeatureClass = null)
{
MessageBox. Show ("select", "system prompt ");
Return;
}
// Call the save file Function
SaveFileDialog sa = new SaveFileDialog ();
Sa. Filter = "SHP file (. shp) | *. shp ";
Sa. ShowDialog ();
Sa. CreatePrompt = true;
String ExportShapeFileName = sa. FileName;
// String StrFilter = "SHP file (. shp) | *. shp ";
// String ExportShapeFileName = SaveFileDialog (StrFilter );
If (ExportShapeFileName = "")
Return;
String ExportFileShortName = System. IO. Path. GetFileNameWithoutExtension (ExportShapeFileName );
String ExportFilePath = System. IO. Path. GetDirectoryName (ExportShapeFileName );
ShpPath = ExportFilePath + "\" + ExportFileShortName + "\" + ExportFileShortName + ". shp ";
// Set the parameters of the exported element class
IFeatureClassName pOutFeatureClassName = new FeatureClassNameClass ();
IDataset pOutDataset = (IDataset) apFeatureClass;
POutFeatureClassName = (IFeatureClassName) pOutDataset. FullName;
// Create a workspace that outputs the shp File
IWorkspaceFactory pShpWorkspaceFactory = new ShapefileWorkspaceFactoryClass ();
IWorkspaceName pInWorkspaceName = new WorkspaceNameClass ();
PInWorkspaceName = pShpWorkspaceFactory. Create (ExportFilePath, ExportFileShortName, null, 0 );
// Create a collection of Elements
IFeatureDatasetName pInFeatureDatasetName = null;
// Create a element class
IFeatureClassName pInFeatureClassName = new FeatureClassNameClass ();
IDatasetName pInDatasetClassName;
PInDatasetClassName = (IDatasetName) pInFeatureClassName;
PInDatasetClassName. Name = ExportFileShortName; // as the output parameter
PInDatasetClassName. WorkspaceName = pInWorkspaceName;
// Use FIELDCHECKER to check the validity of the field and obtain the field set for the output SHP.
Long iCounter;
IFields pOutFields, pInFields;
IFieldChecker pFieldChecker;
IField pGeoField;
IEnumFieldError pEnumFieldError = null;
PInFields = apFeatureClass. Fields;
PFieldChecker = new FieldChecker ();
PFieldChecker. Validate (pInFields, out pEnumFieldError, out pOutFields );
// Search geometric fields cyclically
PGeoField = null;
For (iCounter = 0; iCounter <pOutFields. FieldCount; iCounter ++)
{
If (pOutFields. get_Field (int) iCounter). Type = esriFieldType. esriFieldTypeGeometry)
{
PGeoField = pOutFields. get_Field (int) iCounter );
Break;
}
}
// Obtain the geometric definition of the geometric field
IGeometryDef pOutGeometryDef;
IGeometryDefEdit pOutGeometryDefEdit;
POutGeometryDef = pGeoField. GeometryDef;
// Set the space reference and grid of geometric Fields
POutGeometryDefEdit = (IGeometryDefEdit) pOutGeometryDef;
POutGeometryDefEdit. GridCount_2 = 1;
POutGeometryDefEdit. set_GridSize (0, 1500000 );
Try
{
// Start Import
IFeatureDataConverter pShpToClsConverter = new FeatureDataConverterClass ();
PShpToClsConverter. ConvertFeatureClass (pOutFeatureClassName, null, pInFeatureDatasetName, pInFeatureClassName, pOutGeometryDef, pOutFields, "", 1000, 0 );
MessageBox. Show ("exported successfully", "system prompt ");
}
Catch (Exception ex)
{
MessageBox. Show ("the following exception occurred:" + ex. ToString ());
}
}
}
}