The asker found a way to do this:
Persist the WorkspaceFactory.WorkspaceType of the workspace. Then I
get the workspace factory with this method:
public static IWorkspaceFactory workspaceFactory(esriWorkspaceType type)
if (type == esriWorkspaceType.esriLocalDatabaseWorkspace)
stype = "esriDataSourcesGDB.FileGDBWorkspaceFactory";
else if (type == esriWorkspaceType.esriRemoteDatabaseWorkspace)
stype = "esriDataSourcesGDB.SdeWorkspaceFactory";
Type factoryType = Type.GetTypeFromProgID(stype);
IWorkspaceFactory wsf = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
I don't think this is good coding practice though using hardcoded
strings. I would not have known these strings if I had not found them
in code samples from ESRI.
Is there a better way to do this?
I tried using the Type:
UID uid = workspace.WorkspaceFactory.GetClassID();
Guid guid = new Guid(uid.Value as string);
Type workspaceFactoryType = Type.GetTypeFromCLSID(guid);
This seemed more appealing since it would avoid hardcoded strings:
IWorkspaceFactory wf = Activator.CreateInstance(workspaceFactoryType) as IWorkspaceFactory;
The only problem is that I could not persist Type.