I get a Table [Streets] not found when I try to convert a shapefile to a geodatabase.
I'm thinking I'll try setting the spatial reference like in this post, http://forums.esri.com/Thread.asp?c=159&f=1707&t=299127
But I'm not sure what the steps are to get a GeometryDefEdit from my converter code
//input
IWorkspaceName pInShpWorkspaceName = new WorkspaceNameClass() as IWorkspaceName;
pInShpWorkspaceName.PathName = shapeFileDirectory;
pInShpWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
IFeatureClassName pFCName = new FeatureClassNameClass() as IFeatureClassName;
IDatasetName pShpDatasetName = pFCName as IDatasetName;
pShpDatasetName.Name = shapeFileName;//this is your input file
pShpDatasetName.WorkspaceName = pInShpWorkspaceName;
IName sourceName = (IName)pFCName;
IFeatureClass sourceFeatureClass = (IFeatureClass)sourceName.Open();
IFields sourceFields = sourceFeatureClass.Fields;
//output
IWorkspaceName pWorkspaceName = new WorkspaceNameClass() as IWorkspaceName;
pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesGDB.FileGDBWorkspaceFactory";
pWorkspaceName.PathName = GDBPath; //output file
IFeatureClassName pOutputFC = new FeatureClassNameClass();
IDatasetName pDataSetName = pOutputFC as IDatasetName;
pDataSetName.WorkspaceName = pWorkspaceName;
pDataSetName.Name = "Streets";
IFeatureDataConverter pShpToFc = new FeatureDataConverterClass();
pShpToFc.ConvertFeatureClass(pFCName, null, null, pOutputFC, null, sourceFields, "", 1000, 0);
Also is there anything else I should try ?
I guess it was the 5th Param into ConvertFeatureClass, but unfortunately it didn't make any difference.
*****Update*****
So I did the following operation:
ConvertFieldName(sourceFields, "CITY", "CITY3"); //change column name from city to city3
void ConvertFieldName(IFields fields, string oldname, string newname)
{
if (string.IsNullOrEmpty(oldname)) return;
if (newname == oldname) return;
List<string> fieldnames = GetFieldNames(fields);
IFieldsEdit editfields = fields as IFieldsEdit;
int index = editfields.FindField(oldname);
if (index != -1)
{
IField field = editfields.get_Field(index);
IFieldEdit addresspd = field as IFieldEdit;
addresspd.Name_2 = newname;
addresspd.AliasName_2 = newname;
}
}
And also I try this: (Change column name, and change it back)
ConvertFieldName(sourceFields, "CITY", "CITY3");
ConvertFieldName(sourceFields, "CITY3", "CITY");
Seems insane, I know, but for some reason, doing these operations (either changing or changing back and forth) allowed the GDB file to be created. I guess the code was cleaning up a resource or something, which allowed for the GDB creation.