Saturday 28 March 2015

arcobjects - How to distinguish between File and Personal Geodb workspace?


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();
factory.OpenFromFile(workspace.PathName);
// 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?



Answer



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();
Debug.Print(uid.Value.ToString());

IWorkspaceFactory factory2 = new AccessWorkspaceFactory();
ESRI.ArcGIS.esriSystem.UID uid2 = factory2.GetClassID();
Debug.Print(uid2.Value.ToString());

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...