ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Core Namespace / IItemFactory Interface / GetDataset Method
The item to check.
Example

In This Topic
    GetDataset Method (IItemFactory)
    In This Topic
    Gets the ArcGIS.Core.Data.Dataset associated with the item corresponding to Item.Path. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Dataset GetDataset( 
       Item item
    )
    Function GetDataset( _
       ByVal item As Item _
    ) As Dataset

    Parameters

    item
    The item to check.

    Return Value

    A specific ArcGIS.Core.Data.Dataset (e.g., ArcGIS.Core.Data.FeatureClass) associated with the item. A NotSupportedException will be thrown if the dataset cannot be determined for the item. Use CanGetDataset to determine if the dataset can be retrieved before calling this.
    Exceptions
    ExceptionDescription
    A geodatabase-related exception has occurred.
    This method or property must be called within the lambda passed to QueuedTask.Run
    The dataset cannot be determined for this item. Check CanGetDataset prior to calling this.
    item is null.
    Example
    Geodatabase Content from Browse Dialog
    {
      var openDlg = new OpenItemDialog
      {
        Title = "Select a Feature Class",
        InitialLocation = @"C:\Data",
        MultiSelect = false,
        BrowseFilter = BrowseProjectFilter.GetFilter(ItemFilters.GeodatabaseItems_All)
      };
      //show the browse dialog
      bool? ok = openDlg.ShowDialog();
      if (!ok.HasValue || openDlg.Items.Count == 0)
      {
        // nothing selected, leave
      }
    
      var mapView = MapView.Active;
      await QueuedTask.Run(() =>
      {
        // get the item
        var item = openDlg.Items.First();
        // see if the item has a dataset
        if (ItemFactory.Instance.CanGetDataset(item))
        {
          // get it
          using var ds = ItemFactory.Instance.GetDataset(item);
          // access some properties
          var name = ds.GetName();
          var path = ds.GetPath();
          // if it's a featureclass
          if (ds is FeatureClass fc)
          {
            // create a layer
            var featureLayerParams = new FeatureLayerCreationParams(fc)
            {
              MapMemberIndex = 0
            };
            var layer = LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerParams, mapView.Map);
    
            // continue
          }
        }
      });
    }
    Geodatabase Content from Catalog selection
    {
      // subscribe to event
      ProjectWindowSelectedItemsChangedEvent.Subscribe(async args =>
      {
        if (args.IProjectWindow.SelectionCount > 0)
        {
          // get the first selected item
          var selectedItem = args.IProjectWindow.SelectedItems.First();
          var mapView = MapView.Active;
    
          await QueuedTask.Run(() =>
          {
            // datasetType
            var dataType = ItemFactory.Instance.GetDatasetType(selectedItem);
            // get the dataset Definition
            if (ItemFactory.Instance.CanGetDefinition(selectedItem))
            {
              using var def = ItemFactory.Instance.GetDefinition(selectedItem);
              if (def is FeatureClassDefinition fcDef)
              {
                var oidField = fcDef.GetObjectIDField();
                var shapeField = fcDef.GetShapeField();
                var shapeType = fcDef.GetShapeType();
              }
              else if (def is ArcGIS.Core.Data.Parcels.ParcelFabricDefinition pfDef)
              {
                string ver = pfDef.GetSchemaVersion();
                bool enabled = pfDef.GetTopologyEnabled();
              }
            }
            // get the dataset
            if (ItemFactory.Instance.CanGetDataset(selectedItem))
            {
              using var ds = ItemFactory.Instance.GetDataset(selectedItem);
              if (ds is FeatureDataset fds)
              {
                // open featureclasses within the feature dataset
                // var fcPoint = fds.OpenDataset<FeatureClass>("Point");
                // var fcPolyline = fds.OpenDataset<FeatureClass>("Polyline");
              }
              else if (ds is FeatureClass fc)
              {
                var name = fc.GetName() + "_copy";
                // create
                var featureLayerParams = new FeatureLayerCreationParams(fc)
                {
                  Name = name,
                  MapMemberIndex = 0
                };
                LayerFactory.Instance.CreateLayer<FeatureLayer>(featureLayerParams, mapView.Map);
              }
              else if (ds is Table table)
              {
                var name = table.GetName() + "_copy";
                var tableParams = new StandaloneTableCreationParams(table)
                {
                  Name = name
                };
                // create
                StandaloneTableFactory.Instance.CreateStandaloneTable(tableParams, mapView.Map);
              }
            }
          });
        }
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also