jfisher102

Problem with workspace names returned from GxDialog

Discussion created by jfisher102 on Aug 24, 2011
This code used to work in ArcMap 9.3, but not now in 10.0:

        Dim aoGxDialog As IGxDialog = New GxDialog
        Try
            With aoGxDialog
                .AllowMultiSelect = False
                .Title = strDialogTitle
                .ObjectFilter = New GxFilterWorkspaces
            End With

            Dim aoGxSelect As IEnumGxObject = Nothing
            If Not aoGxDialog.DoModalOpen(oOwner.Handle, aoGxSelect) Then Return Nothing

            Dim aoGxObject As IGxObject = aoGxSelect.Next()
            strReturnDbName = aoGxObject.Name

            If TypeOf aoGxObject Is IGxDatabase Then
                Return CType(aoGxObject, IGxDatabase).Workspace
            ElseIf TypeOf aoGxObject Is IGxFolder Then
                With CType(aoGxObject, IGxFolder)
                    Dim oEnumName As IEnumName = .FileSystemWorkspaceNames
                    Return oEnumName.Next.Open
                End With
            Else
                Throw New Exception("Unexpected workspace type.")
            End If
        Catch ex As Exception
            Throw
        Finally
            GenTools.ReleaseComObject(aoGxDialog)
        End Try


The problem is that when you select a folder containing shapefiles, the oEnumName.Next.Open returns a workspace derived from a TextFileWorkspaceFactory, not a ShapefileWorkspaceFactory.  So the workspace returned does not work with IFeatureWorkspace.OpenFeatureClass().

I had to call my own function with the workspace pathname to create a usable IFeatureWorkspace in ArcMap 10:

                    Dim oWsName As IWorkspaceName = oEnumName.Next
                    Return GetShapefileWorkspace(oWsName.PathName)

    Friend Shared Function GetShapefileWorkspace(ByVal strFoldername As String) As IWorkspace
        '11/11/2008 jaf
        Dim objWSF As IWorkspaceFactory = Nothing
        '================================
        Try
            objWSF = New ShapefileWorkspaceFactory
            Return objWSF.OpenFromFile(strFoldername, 0)
        Catch ex As Exception
            Return Nothing
        Finally
            GenTools.ReleaseComObject(objWSF)
        End Try

    End Function

Outcomes