Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I load up two layers, and then save an .mxd file. Now I want to get the path names of my layers from the .mxd file. Is there a way to do this in ArcEngine?

I'm using ArcEngine 10 with VS2010 & C#

share|improve this question
up vote 6 down vote accepted

Using the MapDocument CoClass, you can do this (pseudocode, I don't know any .Net languages):

void handle_layer(layer, data_sources)
    data_layer = layer as IDataLayer
    group_layer = layer as ICompositeLayer

    if (data_layer != null)

    if (group_layer != null)
       layer_count = group_layer.Count
       for (layer_index in 0..layer_count)
          handle_layer(group_layer.Layer[layer_index], data_sources)

data_sources = list<string>

mxd = MapDocument as IMapDocument
mxd.Open(filename, "")
map_count = mxd.MapCount
for (map_index in 0..map_count)
  map = mxd.Map[map_index]
  layer_count = map.LayerCount
  for (layer_index in 0..layer_count)
    handle_layer(map.Layer[layer_index], data_sources)

The trick is to get the path string from the IName in each data layer.

If you mean you want the path of the original .lyr file you used to add the layers to the TOC, no, that information is not stored anywhere in the MXD.

share|improve this answer

Your Answer


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.