Here's a function I've used in creating featureclasses. I use the IGXDialog.DoModalSave to get the parameters to send to the function, along with the fields that were created. In this code, I'm creating the fields from an existing dataset (pPointFLayer) and also use its spatial reference to create a line featurelayer.
dim OutputLocation As String
dim OutputFCName As String
dim GDBType As String
Dim pGxDialog As ESRI.ArcGIS.CatalogUI.IGxDialog = New ESRI.ArcGIS.CatalogUI.GxDialog
Dim pShapeFilter As ESRI.ArcGIS.Catalog.IGxObjectFilter = New ESRI.ArcGIS.Catalog.GxFilterShapefiles
Dim pPGDBFilter As ESRI.ArcGIS.Catalog.IGxObjectFilter = New ESRI.ArcGIS.Catalog.GxFilterPGDBFeatureClasses
Dim pFilterCollection As ESRI.ArcGIS.Catalog.IGxObjectFilterCollection
Dim pGeoDataset As ESRI.ArcGIS.Geodatabase.IGeoDataset
Dim pSR As ESRI.ArcGIS.Geometry.ISpatialReference
Dim pSpatRes As ESRI.ArcGIS.Geometry.ISpatialReferenceResolution
Dim pFields As ESRI.ArcGIS.Geodatabase.IFields = New ESRI.ArcGIS.Geodatabase.Fields
Dim pFieldsEdit As ESRI.ArcGIS.Geodatabase.IFieldsEdit
Dim pField As ESRI.ArcGIS.Geodatabase.IField
Dim pFieldEdit As ESRI.ArcGIS.Geodatabase.IFieldEdit
Dim pGeomDefEdit As ESRI.ArcGIS.Geodatabase.IGeometryDefEdit = New ESRI.ArcGIS.Geodatabase.GeometryDef
Dim pClone As ESRI.ArcGIS.esriSystem.IClone
Dim pLineFLayer As ESRI.ArcGIS.Carto.IFeatureLayer = New ESRI.ArcGIS.Carto.FeatureLayer
pGxDialog.Title = "Output Feature Class Name"
pFilterCollection = pGxDialog
pFilterCollection.AddFilter(pPGDBFilter, True)
pFilterCollection.AddFilter(pShapeFilter, False)
If pGxDialog.DoModalSave(0) Then
OutputLocation = pGxDialog.FinalLocation.FullName
OutputFCName = pGxDialog.Name
GDBType = pGxDialog.FinalLocation.Category
End If
pGeoDataset = pPointFLayer
pSR = pGeoDataset.SpatialReference
pSpatRes = pSR
pSpatRes.ConstructFromHorizon()
'create the geometry field
With pGeomDefEdit
.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline
.HasM_2 = False
.HasZ_2 = False
.SpatialReference_2 = pSR
End With
'Create fields for output FC
pFieldsEdit = pFields
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
With pFieldEdit
If GDBType = "Folder" Then
.Name_2 = "FID"
Else
.Name_2 = "ObjectID"
End If
.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeOID
End With
pFieldsEdit.AddField(pField)
pFieldsEdit = pFields
pField = New ESRI.ArcGIS.Geodatabase.Field
pFieldEdit = pField
With pFieldEdit
.Name_2 = "SHAPE"
.Type_2 = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry
.GeometryDef_2 = pGeomDefEdit
End With
pFieldsEdit.AddField(pField)
For i As Integer = 0 To pPointFLayer.FeatureClass.Fields.FieldCount - 1
If pPointFLayer.FeatureClass.Fields.Field(i).Type < 6 Then
pClone = pPointFLayer.FeatureClass.Fields.Field(i)
pFieldsEdit.AddField(pClone.Clone)
End If
Next
pLineFLayer.FeatureClass = CreateFeatureClass(OutputLocation, OutputFCName, GDBType, pFields)
Friend Function CreateFeatureClass(ByVal WorkSpaceName As String, ByVal DatasetName As String, ByVal GDBType As String, ByVal pFields As ESRI.ArcGIS.Geodatabase.IFields) As ESRI.ArcGIS.Geodatabase.IFeatureClass
Dim pWSFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory
Dim pFWSpace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace
Dim pDataset As ESRI.ArcGIS.Geodatabase.IDataset
Try
Select Case GDBType 'the values for this vary with the computer's localization. This is the English language version.
Case "Folder"
pWSFactory = New ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactory
Case "Personal Geodatabase"
pWSFactory = New ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactory
Case "File Geodatabase"
pWSFactory = New ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory
Case Else
System.Windows.Forms.MessageBox.Show("Incorrect GDBType!", "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error)
Return Nothing
End Select
pFWSpace = pWSFactory.OpenFromFile(WorkSpaceName, 0)
Try
pDataset = pFWSpace.OpenFeatureClass(DatasetName)
Catch ex As Exception
'do nothing here
End Try
If Not pDataset Is Nothing Then
If pDataset.CanDelete Then
pDataset.Delete()
Else
System.Windows.Forms.MessageBox.Show("Cannot delete existing dataset " & pDataset.Name)
Return Nothing
End If
End If
Return pFWSpace.CreateFeatureClass(DatasetName, pFields, Nothing, Nothing, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, "Shape", "")
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function