How to access maps and layers via the MapDocument

Accessing maps and layers via the MapDocument

The MapDocument class is a utility class for reading and modifying map documents (.mxds).  This document demonstrates how to open a map document and loop through all its maps and layers. In this example, the names of these objects are reported to the console. See the following:
static void openMXDViaMapDocument(String path)throws Exception{
    IMapDocument mapDoc = new MapDocument();
    if (mapDoc.isMapDocument(path)){, null);
        IMap map;
        for (int i = 0; i <= mapDoc.getMapCount() - 1; i++){
            map = mapDoc.getMap(i);
            IEnumLayer enumLayers = map.getLayers(null, true);
            ILayer layer =;
            while (layer != null){
                layer =;


Development licensingDeployment licensing
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine