Hi, I have been struggling for a long time now trying to replicate the functionality of the python code: lyr.dataSource where lyr is a layer in the map. This returns something like: \\Data\lakes.sdc\lakes for a GD \\Data\lakes.shp for a shapefile \\Data\lakes.jpg for a image etc.
I have followed this example: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#//004900000092000000 However the following code: Return (dataset.Workspace.PathName & "\" & dataset.Name) Does NOT return what I need. The .pathName returns the path which is fine but the .Name is the Layers DISPLAY name (what it is called in the map. It is NOT the name of the source file and does not include the file extension.
So what object and property will return the source file name?
Are you sure you didn't try IDataset.BrowseName instead of .Name? And you did include the extra "\" in between, right? This is important... Otherwise, try IDataset.FullName.NameString.
My first error was that I was not using the Feature Class. ILayer2 pLayer; //Inside standard layer loop: pFLayer = pLayer as IFeatureLayer2; IDataset dataset = pFLayer.FeatureClass as IDataset;
dataset.FullName.NameString; returns nothing (null) dataset.Workspace.PathName; returns the folder path dataset.Name; does now that I am using the FeatureClass return the file name with NO extension. dataset.BrowseName; returns the same as dataset.Name.
then I am using: currentLExtention = pFLayer.DataSourceType.ToString(); if (currentLExtention.Contains("Shapefile")) currentLExtention = ".shp"; else currentLExtention = "";
to get the shape file extension.
Interestingly for a raster data-set all I need is: IRasterLayer pRLayer = pLayer as IRasterLayer; currentLName = pRLayer.FilePath;//provides the file path AND the file name WITH the extension. Too bad it can't be this simple for a feature layer.