ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Core Namespace / ItemFactory Class / CanGetDataset Method
The item to check.
Example

In This Topic
    CanGetDataset Method (ItemFactory)
    In This Topic
    Gets if the dataset for the item can be retrieved.
    Syntax
    Public Function CanGetDataset( _
       ByVal item As Item _
    ) As Boolean
    public bool CanGetDataset( 
       Item item
    )

    Parameters

    item
    The item to check.

    Return Value

    True if the dataset can be retrieved. False otherwise.
    Remarks
    Currently only the types listed within ArcGIS.Core.Data.DatasetType are supported. Others items such as network datasets, parcel fabric datasets, BIM datasets will return false.
    Example
    Geodatabase Content from Catalog selection
    {
      // subscribe to event
      ProjectWindowSelectedItemsChangedEvent.Subscribe(args =>
      {
        if (args.IProjectWindow.SelectionCount > 0)
        {
          // get the first selected item
          var selectedItem = args.IProjectWindow.SelectedItems.First();
    
          // Note: Needs QueuedTask to 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.Active.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.Active.Map);
            }
          }
        }
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also