Select to view content in your preferred language

opening a .csv table in VB.NET crashes ArcMap

1463
5
06-06-2011 12:40 PM
KevinAndras
Emerging Contributor
Hi, this code works fine for opening a .dbf, but ArcMap will crash if pTableName is a .csv file.  I can't figure out what to do. Thanks for any help!

        Dim workspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory = New ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass
        Dim workspace As ESRI.ArcGIS.Geodatabase.IWorkspace = workspaceFactory.OpenFromFile(pPath, 0)
        Dim featureWorkspace As ESRI.ArcGIS.Geodatabase.IFeatureWorkspace = CType(workspace, ESRI.ArcGIS.Geodatabase.IFeatureWorkspace) ' Explict Cast
        Return featureWorkspace.OpenTable(pTableName)  'crashes here if table is a .csv
0 Kudos
5 Replies
AlexanderGray
Honored Contributor
0 Kudos
KevinAndras
Emerging Contributor
Now trying TextFileWorkspaceFactory, crashes when I open the table.

Error info:
System.Runtime.InteropServices.COMException was caught
  ErrorCode=-2147220655
  HelpLink="esri_csGeoDatabase.hlp"
  Message=""
  Source=""
  StackTrace:......


   Public Function OpenCSV(ByVal pReachPath As String, ByVal pTableName As String) As ITable

        'textfile workspacefactory
        Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesOleDB.TextFileWorkspaceFactory")
        Dim workspaceFactory As IWorkspaceFactory = CType(Activator.CreateInstance(factoryType), IWorkspaceFactory)

        ' Open a directory of CSV files using its path.
        Dim workspace As IWorkspace = workspaceFactory.OpenFromFile(pReachPath, 0)

        ' Open a CSV file as a table.
        Dim featureWorkspace As IFeatureWorkspace = CType(workspace, IFeatureWorkspace)
        Try

            pTable = featureWorkspace.OpenTable(pTableName) 'crash here
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        Return table

    End Function
0 Kudos
AlexanderGray
Honored Contributor
If you have ArcMap, can you add the csv in ArcMap?  It could be a corrupt file...
0 Kudos
KevinAndras
Emerging Contributor
The table is fine.  I can open it in ArcMap without any problems. It's a table that the old VBA code (which I'm re-coding to VB.Net) used regularly.
0 Kudos
KevinAndras
Emerging Contributor
solved it, that was dumb. I forgot to put the file extension in the file name.
0 Kudos