I am trying to open a CSV file in with the following code:
// Create pTable from .csv file...
IWorkspaceFactory pFact = new TextFileWorkspaceFactory();
IWorkspace pWorkspace = pFact.OpenFromFile(LocalFolder, 0);
IFeatureWorkspace pFeatws = (IFeatureWorkspace)pWorkspace;
ITable pTable = pFeatws.OpenTable(CSVFile); //open the .csv file...
This is throwing me an error. I have opened the csv in ArcMap and it loads fine. I have tried to do the Tyep.GetTypeFromProgID as well and both throw the same error. This is a high priority and have very limited time to get this working. Please someone help me figure this out. The CSVFile does include the file extension as well.
URGENT!! URGENT!!
I also want to mention, this worked in 9.3!!
Hi Elizabeth,
At first check what you have in your pWorkspace. Add code using:
public IEnumDataset get_Datasets (
esriDatasetType DatasetType
);
parameter esriDTTable.
Using Next() from IEnumDataset check all datasets in your workspace. If you find your CSVFile dataset, you can cast it to ITable. Otherwise your csv does not exist or it is wrong.
Gintautas Kmieliauskas I did figure out what was causing my CSV open issue. I was sending the whole path instead of just the file name. I am able to open my csv now, but having issues creating the feature class. This is what I have from 9.3 but it fails when trying to create the Feature Class.
ShapefileWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(LocalFolder, 0);
IFields pMatchFields = geocoder.MatchFields; // Fields from Locator
IFieldsEdit pTableFieldsEdit = (IFieldsEdit)pTable.Fields; // Fields from ActiveCalls.csv
IFieldsEdit pOutputFields = (IFieldsEdit)new Fields();
IFields pTableFields = pTableFieldsEdit;
pOutputFields.FieldCount_2 = pTableFields.FieldCount + pMatchFields.FieldCount + 1;
IFieldEdit pFieldEdit = (IFieldEdit)new Field();
pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
pFieldEdit.Name_2 = "FID";
// Add FID Field
pOutputFields.set_Field(0, pFieldEdit);
// add the fields from the .csv table
for (int i = 1; i <= pTableFields.FieldCount; i++)
pOutputFields.set_Field((i), pTableFields.get_Field(i - 1));
// add the match fields From Locator
for (int i = (1 + pTableFields.FieldCount); i <= (pMatchFields.FieldCount + pTableFields.FieldCount); i++)
{
pOutputFields.set_Field(i, pMatchFields.get_Field(i - pTableFields.FieldCount - 1));
pFeatureClass = pFeatureWorkspace.CreateFeatureClass(ShapeFileName, validatedFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
It's not possible for anyone to provide an answer as you are not showing the full code, what are the variables ShapeFileName and validatedFields set to?
This has now been resolved. Thanks everyone for your input!! It is greatly appreciated!!