Layer myLayer = null;
String sName = "ABC123";
Map map = MapView.Active.Map;
IEnumerable<Layer> matches = map.GetLayersAsFlattenedList().Where(l => l.Name.IndexOf(sName, StringComparison.CurrentCultureIgnoreCase) >= 0);
int index = 0;
if (matches.Count() == 1)
myLayer = matches.FirstOrDefault();
//index = position???
How do you insert it at the same location I originally found it ?
myLayer = LayerFactory.Instance.CreateGroupLayer(MapView.Active.Map, index, sName);
By 'position' I'm assuming you are referring to the position in the Layers collapsible group in the Contents pane.
You can find the index by iterating over the layer list MapView.Map.Layers via a for or foreach loop.
for(int index = 0; index < MapView.Map.Layers.Count; index++)
if (myLayer == MapView.Map.Layers[index])
Also when I did something similar I found a problem in SDK version 2.4 where LayerFactory.Instance.CreateGroupLayer() would only add the layer group to the 2D layers list, which may not be what you want if working with a 3D scene. You will have to add it as its own layer.