Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am having a .gdb file(World.gdb). I want to display or i want to see the content of this gdb file in winForms programmatically(C#). How can i do it? I dont want to view via ArcCatalog.

Please help soon.

Regards, Arun

share|improve this question
    
Are you just trying to display the attributes (feature class names, feature count, etc) in the form or display the actual shape like the Preview tab in ArcCatalog? –  Rich Wawrzonek Jan 22 '13 at 21:57
    
I am performing geoprocessing tools (buffer analysis) on featureclasses. I just want to see whether gp.Execute() method has created output Featureclass or no? and for that i dont want to use ArcCatalog. –  Arun Yegi Jan 23 '13 at 3:39
    
You could use the IGPUtilities.Exists method, which returns whether the object referred to by the given geoprocessing value object exists. –  kenbuja Jan 23 '13 at 13:27

3 Answers 3

Since file geodatabase is a proprietary format, you need to use Esri tools or other software (for example, FME) that has embedded this format.

Meantime, you are welcome to try the File GDB API Esri has released some time ago.

share|improve this answer

I find it handy to put INames in a Dictionary. Opening only open the featureclass when it is needed. Getting a list of INames is much less costly than getting a list of references to featureclasses (or tables).

public static Dictionary<string, IName> GetNames(IWorkspace ws)
{
    var outDict = new Dictionary<string, IName>(StringComparer.CurrentCultureIgnoreCase);

    IEnumDatasetName enumDSname = ws.get_DatasetNames(esriDatasetType.esriDTAny);
    if (enumDSname == null)
        return outDict;

    enumDSname.Reset();
    IDatasetName dsn;
    while ((dsn = enumDSname.Next()) != null)
    {
        outDict.Add(dsn.Name, (IName)dsn);
        var fdsn = dsn as IFeatureDatasetName;
        if (dsn is IFeatureDatasetName)
        {
            var enumDSname2 = dsn.SubsetNames;
            if (enumDSname2 != null)
            {
                IDatasetName dsn2;
                while ((dsn2 = enumDSname2.Next()) != null)
                {
                    outDict.Add(dsn2.Name, (IName)dsn2);
                }
            }
        }
    }
    return outDict;
}

Also, Esri recommends using Activator to instantiate the workspacefactory.

public static IWorkspace OpenWS(string gdbPath)
{
    var type = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
    var wsf = (IWorkspaceFactory)Activator.CreateInstance(type);
    if (!System.IO.Directory.Exists(gdbPath))
        throw new Exception("directory not found: " + gdbPath);
    if (!wsf.IsWorkspace(gdbPath))
        throw new Exception("not really a file gdb: " + gdbPath);
    return wsf.OpenFromFile(gdbPath, 0);
}
share|improve this answer

You can get feature class names from the .gdb file using IWorkspace interface, if you want to get get all feature class names. Then check if your desire feature class is present here or not.

Code is not tested

EDIT

List<string> GetAllDatasetNames(string gdbFilePath)
{
     IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory()
     IWorkspace workspace = workspaceFactory.OpenFromFile (gdbFilePath, 0);
     IEnumDataset enumDataset = workspace.get_Datasets(esriDatasetType.esriDTAny);
     List<string> names = new List<string>();
     IDataset dataset = null;
     while((dataset = enumDataset.Next())!= null)
     {
          names.Add(dataset.Name);
     }
     return names;
}
share|improve this answer
    
As I wrote the full code here, there can be some error. So dont copy-paste please –  Emi Jan 31 '13 at 17:34
    
This will not include names of things inside of a featuredataset. –  Kirk Kuykendall Jan 31 '13 at 18:18
    
@KirkKuykendall But the question does not ask for things inside feature dataset. It asks for things inside gdb. In that sense my answer is not wrong –  Emi Feb 1 '13 at 6:35
    
If a featureclass is inside of a featuredataset which is inside a gdb, then the featureclass is in the gdb. –  Kirk Kuykendall Feb 1 '13 at 14:11

Your Answer

 
discard

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.