1

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?

2 Answers 2

2

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.

4
  • Thanks, Petr, but is GetSaveTableInGxDialog a function or reference to the IGxDialog? I get an error when trying to cast a GxDialog to an IGxObject.
    – kenbuja
    Commented Apr 13, 2012 at 13:33
  • The GetSaveTableInGxDialog opens up a GxDialog, calls its DoModalSave method and returns the table (as an IGxObject) which is to be saved. Based on your question, I assumed you do already call DoModalSave, right?
    – Petr Krebs
    Commented Apr 16, 2012 at 20:40
  • I can get the GxObject using pGxDialog.FinalLocation. I'm having a problem in the next line of your code code, unless it's a question of C# vs. VB. How can you go from the InternalObjectName (an IName) to a IDatasetName? Dim datasetName As IDatasetName = DirectCast(gxObject.InternalObjectName, IDatasetName) results in an error "Unable to cast...No such interface supported"
    – kenbuja
    Commented Apr 17, 2012 at 18:51
  • Right, my bad. The FinalLocation property returns the location where the table will be saved, not a table object. Thus, depending on where you save the table, the FinalLocation.InternalObjectName will be either directly a IWorkspaceName or a IDatasetName (from which you can get to the IWorkspaceName). I'll post an updated and more complete code sample when I get to it.
    – Petr Krebs
    Commented Apr 17, 2012 at 19:49
0

I ended up using the Geoprocessing Tool "CreateFeatureclass" to do this operation.

Here's the code in how I did it (pSR is an ISpatialReference set elsewhere and cboType.Text is a selection of Point, Line, or Polygon):

Dim pGxDialog As New ESRI.ArcGIS.CatalogUI.GxDialog
Dim pFCFilter As New ESRI.ArcGIS.Catalog.GxFilterFeatureClasses
Dim pFClass As ESRI.ArcGIS.Geodatabase.IFeatureClass

pGxDialog.Title = "Create a Feature Class"
pGxDialog.Name = ""
pGxDialog.ObjectFilter = pFCFilter

pFClass = CreateFeatureClass(pGxDialog.FinalLocation.FullName, pGxDialog.Name, pSR, cboType.Text, True)

Friend Function CreateFeatureClass(ByVal FCLocation As String, ByVal FCName As String, ByVal pSR As ESRI.ArcGIS.Geometry.ISpatialReference3, ByVal GeometryType As String, Optional ByVal AddLayer As Boolean = False) As ESRI.ArcGIS.Geodatabase.IFeatureClass

    Dim CreateFClass As New ESRI.ArcGIS.DataManagementTools.CreateFeatureclass
    Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

    Try
        Using releaser As New ESRI.ArcGIS.ADF.ComReleaser
            releaser.ManageLifetime(CreateFClass)

            CreateFClass.out_path = FCLocation
            CreateFClass.out_name = FCName
            CreateFClass.spatial_reference = pSR
            CreateFClass.geometry_type = GeometryType

            Result = RunTool(CreateFClass, Nothing, AddLayer)
            If Result Is Nothing Then Return Nothing

            Return ReturnObjectfromResult(Result, "Feature Class")

        End Using
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.ToString & vbNewLine & ex.StackTrace.ToString, "Create Feature Class")
        Return Nothing
    End Try

End Function

Friend Function RunTool(ByVal Process As ESRI.ArcGIS.Geoprocessor.IGPProcess, ByVal TC As ESRI.ArcGIS.esriSystem.ITrackCancel2, Optional ByVal AddOutput As Boolean = False) As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

    Dim Result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2

    Try
        System.Windows.Forms.Cursor.Current = Windows.Forms.Cursors.WaitCursor
        Dim GP As New ESRI.ArcGIS.Geoprocessor.Geoprocessor

        GP.AddOutputsToMap = AddOutput

        Result = CType(GP.Execute(Process, Nothing), ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2)
        If Result.Status <> ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded Then System.Windows.Forms.MessageBox.Show("Geoprocessing Error")
        GP.ClearMessages()
    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.ToString, "Run Geoprocessor")
    End Try

    Return Result

End Function

Friend Function ReturnObjectfromResult(ByVal result As ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult2, ByVal Type As String) As Object

    Dim GPVal As ESRI.ArcGIS.Geodatabase.IGPValue
    Dim InMemFC As String
    Dim GPUtil As ESRI.ArcGIS.Geoprocessing.IGPUtilities3 = New ESRI.ArcGIS.Geoprocessing.GPUtilities

    Try
        GPVal = result.GetOutput(0)
        InMemFC = GPVal.GetAsText()

        Select Case Type
            Case "Feature Class"
                Return GPUtil.OpenFeatureClassFromString(InMemFC)
            Case "Table"
                Return GPUtil.OpenTableFromString(InMemFC)
            Case "Feature Layer"
                Return GPUtil.OpenFeatureLayerFromString(InMemFC)
            Case Else
                Return Nothing
        End Select

    Catch ex As Exception
        System.Windows.Forms.MessageBox.Show(ex.ToString, "Return FeatureClass error")
        Return Nothing
    End Try

End Function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.