How to add a layer to a map from a layer file

This article illustrates how to open a layer file and add the layer to a map in the code.

Adding a layer to a map from a layer file

This operation is performed using the MapDocument class, which can open layer files, as well as map documents (.mxds) and published map files (.pmfs). See the following code:
static void addLayerFileToMap(IMap map, String path)throws Exception{
    IMapDocument document = new MapDocument();
    //Use the map document class to open the layer., "");
    //When opening a layer with the map document class,
    //the layer is added to a new document as the first
    //layer in the first map.

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