For those of you familiar with ArcObjects, you may have found yourself needing to determine whether or not a particular dataset exists given nothing but the name of the dataset, its expected type, and a workspace.  ESRI has many dataset types, including, but not limited to…feature class, table, feature dataset, geometric network, raster dataset, and TIN (the list goes on).

One way to go about retrieving this information is by using the IWorkspace2 interface.  For instance, if you are given the name “overhead_transformer” and a workspace, and you are trying to find out whether or not a feature class by this name exists, you can do the following…


IWorkspace2 workspace2 = (IWorkspace2)workspace;

bool exists = workspace2.get_NameExists(esriDatasetType.esriDTFeatureClass, “overhead_transformer”)


Seems pretty straightforward, but what about if we’re dealing with SDE and the name in the SDE database is prepended with a schema name (e.g. Oracle SDE, and the real name is ELEC.overhead_transformer)?  You will find that this same code works…but only with more recent versions of ArcGIS Desktop.

We were recently dealing with a client running ArcGIS Desktop 10.2.1, and finding that the code above, which worked with all of our other clients, did not seem to be working.  The only real difference we could see was the version of ArcGIS Desktop being used.

Therefore, we modified the check to work differently.  Up-front, we cache all the feature class and table names in the ESRI database, along with their type, as-follows:


Queue<IEnumDatasetName> namesToCheck = new Queue<IEnumDatasetName>();


IEnumDatasetName currentEnum = null;

IDatasetName dsName = null;


while (namesToCheck.Count > 0)


                currentEnum = namesToCheck.Dequeue();


                while ((dsName = currentEnum.Next()) != null)


                                if ((dsName.Type == esriDatasetType.esriDTFeatureDataset) && (dsName.SubsetNames != null))


                                else if ((dsName.Type == esriDatasetType.esriDTFeatureClass) || (dsName.Type == esriDatasetType.esriDTTable))

                                                // Cache the name and type of the dataset.




Why caching?  Because the above code takes significantly longer to run through than get_NameExists, so caching the information we really want allows us access to it in a very timely manner if we search repeatedly.

Finally, when checking whether or not a given name (e.g. “overhead_transformer”) has a match, we loop through our cached names, compare them both with a ToLower call, but also split the cached name on a period and compare the name to the last piece of the split string so that the presence of a schema delineator or some other SDE-specific delineator does not cause us to miss names.  After this, we can find a given feature class or table whether or not the name passed is somewhat ambiguous.


overhead_transformer = ELEC.overhead_transformer

OVERHEAD_TRANSFORMER = overhead_transformer

elec.overhead_transformer = ELEC.overhead_transformer


This solution works with all versions of ArcGIS Desktop against which we’ve tested.