I am working on code in C# (VS 2008 Express) to return an IFeatureClass from both Personal and File Geodatabases against ArcMap 10 using an AddIn. I am having a problem with filters and determining the type. If I set filters for both, I get the following in the dialog filters list:File and Personal GeodatabasesFile GeodatabasesWhy is the first one both types instead of just Personal?Second problem: The gxDialog.FinalLocation.Category always reports "Folder" no matter which type is selected. I've hacked around that by looking at the file extension instead. But, is there a better way to differentiate between File and Personal?Here's the code (without the file ext hack). It will always report "Unsupported Category: Folder". With the hack it works fine:private IFeatureClass GetFeatureClass()
{
// Check if exists, and just return reference if it does
string featureClassName = "Test_FC";
// Setup the dialog to locate the db
IGxDialog gxDialog = new GxDialogClass();
IGxObjectFilter gxObjectFilter_PGDB = new GxFilterPersonalGeodatabasesClass();
IGxObjectFilter gxObjectFilter_FGDB = new GxFilterFileGeodatabasesClass();
IGxObjectFilterCollection gxObjectFilterCollection = (IGxObjectFilterCollection)gxDialog;
gxObjectFilterCollection.AddFilter(gxObjectFilter_PGDB, true);
gxObjectFilterCollection.AddFilter(gxObjectFilter_FGDB, false);
gxDialog.Title = "Select the Project Geodatabase";
if (gxDialog.DoModalSave(0))
{
string workspaceName = gxDialog.FinalLocation.FullName + "/" + gxDialog.Name;
string workspaceCategory = gxDialog.FinalLocation.Category;
//string workspaceCategory = System.IO.Path.GetExtension(gxDialog.Name).ToLower();
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory;
switch (workspaceCategory)
{
case "Personal Geodatabase":
//case ".mdb":
MessageBox.Show(featureClassName + "Detected Personal Geodatabase");
workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass();
break;
case "File Geodatabase":
//case ".gdb":
MessageBox.Show(featureClassName + "Detected File Geodatabase workspace");
workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass();
break;
default:
MessageBox.Show("Unsupported Category: " + workspaceCategory);
return null;
}
ESRI.ArcGIS.Geodatabase.IWorkspace workspace = workspaceFactory.OpenFromFile(workspaceName, 0);
ESRI.ArcGIS.Geodatabase.IWorkspace2 workspace2 = (ESRI.ArcGIS.Geodatabase.IWorkspace2)workspace;
ESRI.ArcGIS.Geodatabase.IFeatureWorkspace featureWorkspace = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)workspace; // Explicit Cast
if (workspace2.get_NameExists(ESRI.ArcGIS.Geodatabase.esriDatasetType.esriDTFeatureClass, featureClassName))
{
ESRI.ArcGIS.Geodatabase.IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(featureClassName);
if (featureClass != null)
{
return featureClass;
}
else
{
MessageBox.Show(featureClassName + " feature class can't be opened. It may be in use by another application.");
return null;
}
}
else
{
MessageBox.Show(featureClassName + " feature class does not exist.");
return null;
}
}
else
{
MessageBox.Show("Dialog cancelled. Do nothing.");
return null;
}
}
Thanks for any help.-Jeff Hamblin