Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When a user loads an mxd, I am getting the IWorkspace object from the featurelayer's dataset:

IFeatureClass featClass = (IFeatureClass)featLayer.FeatureClass;
IDataset dataSet = (IDataset)featClass.FeatureDataset;
IWorkspace workSpace = (IWorkspace)dataSet.Workspace;

But this obviously does not work if the user has a layer from a file geodatabase (dataset is null).

I can check to see if it's a gdb layer but nothing in the featurelayer or its featureclass tells me the source of the gdb.

How do I go about setting the workspace object to a featurelayer that comes from a gdb?

share|improve this question
IS THIS RESOLVED? – ujjwalesri Jun 30 '11 at 5:22
up vote 4 down vote accepted

Change the line

IDataset dataSet = (IDataset)featClass.FeatureDataset;


IDataset dataset = (IDataset)featClass;
share|improve this answer
Simple as that. QI the featclass to the dataset gives me the fgdb path in its workspace property. Thank you very much. – SteveC Jun 30 '11 at 15:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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