I am trying find the best way to find the full path of a shapefile, which is open in the active map. Or in other words, I want to find a way to know if the feature layer in the active map is a shapefile or not. I "think" I saw it somewhere in the SDK snippets github pages, but I cannot track it now. Anyway, here is what I did:
I would be grateful if anyone could help me find a better way to do this. Surely, there must be a better way.
In the above code, I have assigned all feature layer WITHOUT an extension as a FGDB feature class, and others as a shapefile. I think that could run into trouble as well.
Many thanks in advance.
Your technique should work fine.
In the upcoming Pro 2.6 release (summer 2020), we will be adding a GetPath() method directly to the FeatureLayer class so that you don't have to go through this to get the path.
But if you're going through all of this just to find out if you are looking at a shape file, I would do something like this:
bool IsShapeFile(FeatureLayer featureLayer)
using (FeatureClass featureClass = featureLayer.GetFeatureClass())
using (Datastore datastore = featureClass.GetDatastore())
if (datastore is FileSystemDatastore)
I hope this helps,
Thank you very much for your kind and prompt reply. It is very nice to know that such a feature will be available in the next release. Awesome !
Thank you for your script. I saw the snippet for opening a shapefile using "FileSystemDatastore" in the snippet section. But I could not find a way to use it to check for a shapefile. Thank you for sharing a simpler solution. This is really awesome!
Many many thanks again !