private IFeatureClass GetFeatureClassSelection() {
        var gxObject = BrowseForFeatureClass(0);
        if (gxObject == null)
            return null;
        var gxDataset = gxObject as IGxDataset;
        IFeatureClass featureClass = null;
        if (gxDataset != null) {
            if (gxDataset.Dataset == null) {
                MessageBox.Show("Unable to access selected feature class", "File Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return null;
            _selectedFeatureInformation.WorkspaceType = gxDataset.Dataset.Workspace.Type.ToString();
            featureClass = gxDataset.Dataset as IFeatureClass;
        if (featureClass == null) {
            MessageBox.Show("Feature Classes and Shapefiles are allowed only", "File Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
            TxtBxSrcFtrClass.Text = string.Empty;
            return null;
        _selectedFeatureInformation.FtrClass = featureClass;
        TxtBxSrcFtrClass.Text = gxDataset.Dataset.Workspace.PathName + "\\" + ((IDataset)_selectedFeatureInformation.FtrClass).Name;
        return featureClass;

How can I tell if it is a shapefile or feature class from the returned object?


You can get the WorkspaceFactory from the IFeatureClass object and check its type.

IFeatureClass fClass = ...;
esriWorkspaceType fcType = (fClass as IDataset).Workspace.WorkspaceFactory.WorkspaceType;

You could also use WorkspaceFactory.WorkspaceDescription to get a more granular breakdown.


You can find out the workspace type that the dataset utilizes using the code below. From an IDataset, use the Workspace property when calling the function

dim category as String = GetCategory(gxDataset.Dataset.Workspace)

Public Function GetCategory(ByVal pWorkspace As ESRI.ArcGIS.Geodatabase.IWorkspace) As String

    Dim sClassID As String
    sClassID = pWorkspace.WorkspaceFactory.GetClassID.Value

    Select Case sClassID
        Case "{DD48C96A-D92A-11D1-AA81-00C04FA33A15}" ' pGDB
            GetCategory = "Personal Geodatabase"

        Case "{71FE75F0-EA0C-4406-873E-B7D53748AE7E}" ' fGDB
            GetCategory = "File Geodatabase"          '

        Case "{D9B4FA40-D6D9-11D1-AA81-00C04FA33A15}" ' GDB
            GetCategory = "SDE Database"

        Case "{A06ADB96-D95C-11D1-AA81-00C04FA33A15}" ' Shape
            GetCategory = "Shapefile Workspace"

        Case "{34DAE34F-DBE2-409C-8F85-DDBB46138011}" ' SDC
            GetCategory = "SDC Workspace"

        Case "{1D887452-D9F2-11D1-AA81-00C04FA33A15}" ' Coverage
            GetCategory = "ArcInfo Coverage Workspace"

        Case "{7F2BC55C-B902-43D0-A566-AA47EA9FDA2C}" ' InMemory
            GetCategory = "InMemory Workspace"

        Case "{59158055-3171-11D2-AA94-00C04FA37849}" 'OLEDB Workspace
            GetCategory = "OLEDB Workspace"

        Case "{30F6F271-852B-4EE8-BD2D-099F51D6B238}" 'Excel Workspace
            GetCategory = "Excel Workspace"

        Case Else
            GetCategory = "Unknown Workspace Category"
    End Select
End Function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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