This document is archived and information here might be outdated.  Recommended version.

How to access maps and layers via the MapDocument (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Interacting with and configuring maps, layers, and graphics > Working with map documents > How to access maps and layers via the MapDocument

How to access maps and layers via the MapDocument

The MapDocument class is a utility class for reading and modifying map documents (.mxds). This topic demonstrates how to open a map document and loop through all its maps and layers.

Accessing maps and layers via the MapDocument 

In the following code example, the names of these objects are reported to the console. Do the following steps to access maps and layers:
  1. Create a MapDocument.
IMapDocument pMapDocument=new MapDocumentClass();
Dim pMapDocument As IMapDocument=New MapDocumentClass()
  1. Enumerate the maps in the MapDocument and print their names to the console. See the following code example:
if (pMapDocument.get_IsMapDocument(path))
    pMapDocument.Open(path, null);
    IMap pMap;
    for (int i=0; i <= pMapDocument.MapCount - 1; i++)
        IEnumLayer pEnumLayer=pMap.get_Layers(null, true);
        ILayer pLayer=pEnumLayer.Next();
        while (pLayer != null)


If pMapDocument.IsMapDocument(Path) Then
    pMapDocument.Open(Path, Nothing)
    Dim pMap As IMap
    Dim i As Integer
    For i=0 To pMapDocument.MapCount - 1 Step i + 1
        Dim pEnumLayer As IEnumLayer=pMap.Layers(Nothing, True)
        Dim pLayer As ILayer=pEnumLayer.Next()
        While Not pLayer Is Nothing
        End While
End If

Additional Requirements
  • Path - A string that points to the map document you want to open.

Development licensing Deployment licensing
ArcGIS Desktop Basic ArcGIS Desktop Basic
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine