davecouture

List Fields using IWorkspace

Discussion created by davecouture on Dec 20, 2013
Latest reply on Dec 20, 2013 by davecouture
I'm trying to access a Feature Class in a GDB and list its Field Names.  The FC is not in the TOC/ActiveView, I want to access it directly.  This is what I have so far:

Public Sub ListFields()

        Dim fieldList As String = ""
        Dim pFact As IWorkspaceFactory = New AccessWorkspaceFactory
        Dim pWorkspace As IWorkspace = pFact.OpenFromFile("G:\Data\GDB\Production.gdb", 0)
        Dim pFeatureWorkSpace As IFeatureWorkspace = pWorkspace
        Dim pFeatureClass As IFeatureClass = pFeatureWorkSpace.OpenFeatureClass("LandSea")
        Dim fields As IFields = pFeatureClass.Fields
        Dim field As IField = Nothing

        For i As Integer = 0 To fields.FieldCount - 1
            field = fields.Field(i)
            fieldList = fieldList + field.Name + vbNewLine
        Next i

        MsgBox(fieldList)

 End Sub

Outcomes