ArcObjects Library Reference (Controls)  

IMapControl2.AddLayerFromFile Method

Loads a layer file and adds it to the Map's collection of layers at the specified index position.

[Visual Basic .NET]
Public Sub AddLayerFromFile ( _
    ByVal lyrPath As String, _
    [ByVal toIndex As Integer] _
)
[C#]
public void AddLayerFromFile (
    string lyrPath,
    int toIndex
);
[C#]

Optional Values

toIndex   Supply 0 as a default value.
[C++]
HRESULT AddLayerFromFile(
  BSTR lyrPath,
  long toIndex
);
[C++]

Parameters

lyrPath [in]   lyrPath is a parameter of type BSTR toIndex [in, optional, defaultvalue(0)]   toIndex is a parameter of type long

Product Availability

Available with ArcGIS Engine.

Description

When a layer file is added to the MapControl's layer collection and no index is specified, it is added to the beginning or top of the collection with an index of 0. The numeric index of any other layers in the layer collection increments by one.

When a layer file is added and an index is specified, the numeric index of any other layers in the layer collection will increment by one, except for those layers with an index less than the specified index. The index of these layers will remain the same.

Errors Returned

1023 800a03ff: The specified index is out of range

Remarks

The Layer at the beginning or top of the collection with an index of 0 will be drawn last, whilst the Layer at the bottom of the collection will be drawn first.

Use the MoveLayerTo method to change the position of a Layer within the layer collection.

[C#]
//Add layer at index 0
axMapControl1.AddLayerFromFile(@"C:\Temp\myLayer.lyr",0);
//Add layer at index 2
axMapControl1.AddLayerFromFile(@"C:\Temp\myLayer.lyr", 2);
[Visual Basic .NET]
'Add layer at index 0
AxMapControl1.AddLayerFromFile("C:\Temp\myLayer.lyr")
'Add layer at index 2
AxMapControl1.AddLayerFromFile("C:\Temp\myLayer.lyr", 2)

See Also

IMapControl2 Interface | IMapControl3.AddLayer Method | IMapControl4.AddLayer Method | IMapControl2.AddLayer Method | IMapControl3.AddShapeFile Method | IMapControl2.AddShapeFile Method | IMapControl4.AddShapeFile Method