ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Map Class / Layers Property
Example

In This Topic
    Layers Property (Map)
    In This Topic
    Gets a read-only collection of layers from the layer container.
    Syntax
    Example
    Obtaining Geodatabase from FeatureLayer
    public async Task ObtainingGeodatabaseFromFeatureLayer()
    {
      IEnumerable<Layer> layers = MapView.Active.Map.Layers.Where(layer => layer is FeatureLayer);
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        foreach (FeatureLayer featureLayer in layers)
        {
          using (Table table = featureLayer.GetTable())
          using (Datastore datastore = table.GetDatastore())
          {
            if (datastore is UnknownDatastore)
              continue;
    
            Geodatabase geodatabase = datastore as Geodatabase;
          }
        }
      });
    }
    Select all feature layers in TOC
    public void SelectAllFeatureLayersInTOC()
    {
      //Get the active map view.
      var mapView = MapView.Active;
      if (mapView == null)
        return;
    
      //Zoom to the selected layers in the TOC
      var featureLayers = mapView.Map.Layers.OfType<FeatureLayer>();
      mapView.SelectLayers(featureLayers.ToList());
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also