code to open CSV in 10.0 does not work in 10.1

1001
2
12-10-2012 11:11 AM
KevinAndras
New Contributor II
Hi,
My vb.net code for 10.0, which returns ITable, does not work in 10.1.  I've read that 10.1 has a new method for opening text files, but I can't find any details. Anyone solve this problem? Thanks!

Dim pTable As ITable = Nothing
Dim pMxDoc As IMxDocument = My.ArcMap.Document
Dim pMap As IMap = pMxDoc.FocusMap
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesOleDB.TextFileWorkspaceFactory")

'last line in 10.1, exits the function here.
Dim workspaceFactory As ESRI.ArcGIS.Geodatabase.IWorkspaceFactory2 = CType(Activator.CreateInstance(factoryType),IWorkspaceFactory2)

Dim workspace As IWorkspace = workspaceFactory.OpenFromFile(pReachPath, 0)
Dim featureWorkspace As IFeatureWorkspace = CType(workspace, IFeatureWorkspace)
            Try
                pTable = featureWorkspace.OpenTable(pTableName)
            Catch ex As System.Exception
                Return Nothing
            End Try
0 Kudos
2 Replies
KevinAndras
New Contributor II
This code, directly from ArcObjects API Reference for .NET, causes an error ( I replaced pathname and filename with my file):

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("C:\Data\CSV", 0)

' Open a CSV file as a table.
Dim featureWorkspace As IFeatureWorkspace = CType(workspace, IFeatureWorkspace)
Dim table As ITable = featureWorkspace.OpenTable("Levee.csv")

Error comes on the 2nd line, as "factoryType = nothing"

System.ArgumentNullException was caught
  Message=Value cannot be null.
Parameter name: type
  ParamName=type
  Source=mscorlib
  StackTrace:
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Activator.CreateInstance(Type type)
       at NetMap2.modGeneral.OpenCSV(String pPath, String pTableName)
  InnerException:
0 Kudos
KevinAndras
New Contributor II
Well, this works:

                Dim workspaceFactory As IWorkspaceFactory
                workspaceFactory = New DataSourcesOleDB.TextFileWorkspaceFactory
                ' Open a directory of CSV files using its path.
                Dim workspace As IWorkspace = workspaceFactory.OpenFromFile(pPath, 0)
                ' Open a CSV file as a table.
                Dim featureWorkspace As IFeatureWorkspace = CType(workspace, IFeatureWorkspace)
                pTable = featureWorkspace.OpenTable(pTableName)
                Return pTable
0 Kudos