[GIS] Getting the workspace from IGxDialog:DoModalSave

arcgis-10.0arcobjects

I'm writing an application that allows a user to save data into a table in a variety of formats: dBase, File or Personal Geodatabase, or SDE. I'm trying to see if there's a way to determine what type of workspace was chosen in the IGxDialog that is language independent. In a previous version, I was using the IGxDialog.ObjectFilter.Name property, but this varies with localization. On an English language machine, it will return 'dBASE tables', but on a German language machine, it returns 'dBASE-Tabelle'.

I've tried working with the objectfilter, but the following code will give me both messages.

        If TypeOf pObjectFilter Is ESRI.ArcGIS.Catalog.GxFilterdBASEFiles Then MsgBox("Dbase")
        If TypeOf pObjectFilter Is ESRI.ArcGIS.Catalog.GxFilterPGDBTables Then MsgBox("geodatabase")

How can I get a workspace from that dialog and determine what it is using IWorkspace:WorkspaceFactory:ClassID?

Best Answer

The selected gx object (IGxObject) has the InternalObjectName property, which is the name object representing the table.

You can cast the table name object to IDatasetName and navigate to the workspace name (IDatasetName.WorkspaceName), which will give you the factory progid (WorkspaceFactoryProgID property).

IGxObject gxObject = GetSaveTableInGxDialog(); // using the gx dialog, gets the table IGxObject to save
IDatasetName datasetName = (IDatasetName)gxObject.InternalObjectName;
IWorkspaceName workspaceName = datasetName.WorkspaceName;
var progId = workspaceName.WorkspaceFactoryProgID;

if (string.Equals(progId, "esriDataSourcesGDB.SdeWorkspaceFactory", StringComparison.OrdinalIgnoreCase))
{
   ... SDE
}

In most cases though, you probably will not need to know the exact workspace factory, but the general workspace type (IWorkspaceName.Type - file system workspace or local or remote) will suffice.

Related Question