List Fields using IWorkspace

374
1
12-20-2013 08:23 AM
DaveCouture
New Contributor III
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
0 Kudos
1 Reply
DaveCouture
New Contributor III
Got it!  I had to replace this:


Dim pFact As IWorkspaceFactory = New AccessWorkspaceFactory


with this:


Dim pFact As IWorkspaceFactory = New FileGDBWorkspaceFactoryClass()
0 Kudos