I am looking for a way - given an IWorkspace object - to check if it was created from a Personal-GDB or a File-GDB. I tried using IWorkspace.WorkspaceFactory to check if it's an instance of e.g. AccessWorkspaceFactory but unfortunately this doesn't work for the fgdb. According to .NET the fgdb workspace was created by an AccessWorkspaceFactory, too. Duh. So far I've only come up with the idea that one could check if it's an pgdb by trying to create the workspace using the according factory. The same goes for the fgdb, obviously. Like so:

try {
   IWorkspaceFactory factory = new AccessWorkspaceFactoryClass();
   // if we got that far it seems to be a personal gdb
   pgdb = true;
} catch (Exception) {
   pgdb = false; // nope, not a personal gdb (or valid path or whatever)

But this solution doesn't seem to be very elegant. Are there any data structures to check where the workspace came from?


you can use IWorkspaceFactory.GetClassID() method...i just tested on 9.3 and it gives me two values..

AccessWorkspaceFactory -> {DD48C96A-D92A-11D1-AA81-00C04FA33A15}
FileGDBWorkspaceFactory -> {71FE75F0-EA0C-4406-873E-B7D53748AE7E}

the code i used is below..

    IWorkspaceFactory factory = new FileGDBWorkspaceFactoryClass();
    ESRI.ArcGIS.esriSystem.UID uid = factory.GetClassID();

    IWorkspaceFactory factory2 = new AccessWorkspaceFactory();
    ESRI.ArcGIS.esriSystem.UID uid2 = factory2.GetClassID();
  • Thanks, it works as described and I found the UIDs in an old code example. Guess they are meant to last although they are not mentioned in any official document. – AndOne Mar 30 '12 at 10:03

Once you have a reference to the workspace, you can use this function to find out what kind of data source it is. You can find a list of all workspace factory UID values here

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

If you are just after detecting a file vs personal gdb, you could just do a Directory.Exists on the path (file gdbs are directories and personal gdb is for files).

I don't know of a recommended method of determining this, but I have this in an extension method GetWorkspaceContainerType(this IWorkspace workspace) sorry, can't post the entire method. You could put whatever you want in the blocks and return whatever you need .

            IWorkspaceFactory factory = workspace.WorkspaceFactory;

            string s = ((IWorkspaceFactory2)factory).get_WorkspaceDescription(false);


            if (s.Equals("Personal Geodatabase", StringComparison.CurrentCultureIgnoreCase))
                log.Debug("Personal Geodatabase");
            else if (s.Equals("Spatial Database Connection", StringComparison.CurrentCultureIgnoreCase))
                log.Debug("SDE Connection/Spatial Database Connection");
            else if (s.Equals("File Geodatabase", StringComparison.CurrentCultureIgnoreCase))
                log.Debug("File Geodatabase");
                throw new NotImplementedException();
  • Thanks, but can I be sure that those strings won't get localized/changed in the future? – AndOne Mar 30 '12 at 10:05
  • No. I would think that the ClassIDs (@vinayan answer) are a better option. I'll probably look at switching mine over in the future. – Jay Cummins Mar 30 '12 at 10:54

You can use the IWorkspace.WorkspaceFactory property (returns an IWorkspaceFactory reference) to check which whether the workspace object was created from an AccessWorkspaceFactory, FileGDBWorkspaceFactory, or other.

  • Hmm, according to the linked question above this doesn't work... will have to test. – blah238 Jun 18 '12 at 23:24
  • It works. You were correct with your original post. Getting the workspace factory was the ticket. – Jeff Berry Jun 18 '12 at 23:38
  • Ah, I was thinking you could check if the workspace factory "is" an AccessWorkspaceFactory, etc., but in COM this only works for interfaces, not classes. You have to check its class ID as in @kenbuja's answer. – blah238 Jun 19 '12 at 1:25

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.