Select to view content in your preferred language

How do I get the file path of a shapefile or layer loaded in mxd?

5203
3
05-12-2010 02:42 PM
MarioSuau
Emerging Contributor
Hi,

I'm developing using the ArcGIS 9.3 Engine Developer Kit for .net (C#).  I'm using the map control and I have the need to get the actual file path of a shapefile or layer. 

In ArcMap, I can right click on a layer and go to Properties->Source tab.  From there I see the Data source info which includes the path to the shapefile, etc.  I'd like to do something similar.

Does anyone know how to get to this layer or shapefile path information?

Thanks,
Mario Suau
Federal Signal Codespear
0 Kudos
3 Replies
KirkKuykendall
Deactivated User
0 Kudos
MarioSuau
Emerging Contributor
Kirk,

I was able to figure out what I needed based on the link you sent.

Thank you!
Mario
0 Kudos
JoxueOx
New Contributor
had the same issue and looked at the link provided. here is how to do it given an object that can be cast as an IFeatureLayer:

private string FullPathOfLayer(object Item)
{
string fullPath = "";
IFeatureLayer ifl = Item as IFeatureLayer;
IDataset ds = ifl.FeatureClass as IDataset;
fullPath += ds.Workspace.PathName;
fullPath += @"\" + ds.Name;
if (ifl.DataSourceType.ToLower().Contains("shapefile"))
{
fullPath += ".shp";
}
return fullPath;
}
0 Kudos