ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Core.Data Namespace / Geodatabase Class / OpenDataset<T> Method
The type of dataset to open.
The name of the dataset to open.
Example

In This Topic
    OpenDataset<T> Method (Geodatabase)
    In This Topic
    Gets a specific Dataset instance associated with name of type T in the geodatabase. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function OpenDataset(Of T As Dataset)( _
       ByVal name As String _
    ) As T
    public T OpenDataset<T>( 
       string name
    )
    where T: Dataset

    Parameters

    name
    The name of the dataset to open.

    Type Parameters

    T
    The type of dataset to open.

    Return Value

    A specific Dataset instance corresponding to type T.
    Exceptions
    ExceptionDescription

    No valid geodatabase has been opened prior to calling this operation.

    -or-

    The dataset type corresponding to T is not supported (see DatasetType).

    -or-

    Using AttributedRelationshipClass as T to open a dataset whose type is actually DatasetType.RelationshipClass.

    A geodatabase-related exception has occurred. For example, the name is invalid.
    Example
    Opening datasets from Geodatabase
    {
      await QueuedTask.Run(() =>
      {
        using (Geodatabase geodatabase = new Geodatabase(new DatabaseConnectionFile(new Uri("path\\to\\sde\\file\\sdefile.sde"))))
        {
          using (Table table = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.EmployeeInfo"))
          {
          }
    
          // Open a featureClass (within a feature dataset or outside a feature dataset).
          using (FeatureClass featureClass = geodatabase.OpenDataset<FeatureClass>("LocalGovernment.GDB.AddressPoint"))
          {
          }
    
          // Open a FeatureClass as a Table which will return the Table reference.
          using (Table featureClassAsTable = geodatabase.OpenDataset<Table>("LocalGovernment.GDB.AddressPoint"))
          {
            // But it is really a FeatureClass object.
            FeatureClass featureClassOpenedAsTable = featureClassAsTable as FeatureClass;
          }
    
          // Open a FeatureDataset.
          using (FeatureDataset featureDataset = geodatabase.OpenDataset<FeatureDataset>("LocalGovernment.GDB.Address"))
          {
          }
    
          // Open a RelationshipClass.  Just as you can open a FeatureClass as a Table, you can also open an AttributedRelationshipClass as a RelationshipClass.
          using (RelationshipClass relationshipClass = geodatabase.OpenDataset<RelationshipClass>("LocalGovernment.GDB.AddressPointHasSiteAddresses"))
          {
          }
        }
      });
    }
    Opening datasets from a Feature Service by Layer ID
    {
      //Url examples for (federated) feature services
      //(federated by ref on portal)
      var url =
          @"https://portal.example.com/server/rest/services/FeatureServiceName/FeatureServer";
      //(federated by value - Hosted - on portal)
      //https://portal.example.com/server/rest/services/Hosted/FeatureServiceName/FeatureServer
    
      await QueuedTask.Run(() =>
      {
        var uri = new Uri(url, UriKind.Absolute);
        using (var fs_db = new ArcGIS.Core.Data.Geodatabase(new ServiceConnectionProperties(uri)))
        {
          using (FeatureClass featureClass = fs_db.OpenDataset<FeatureClass>("0"))
          {
            // Use the feature class opened from layer ID 0.
          }
    
          using (Table table = fs_db.OpenDataset<Table>("4"))
          {
            // Use the table opened from layer ID 4.
          }
    
          using (AttributedRelationshipClass attributedRelationshipClass =
              fs_db.OpenDataset<AttributedRelationshipClass>("5"))
          {
            // Use the attributed relationship class opened from layer ID 5.
          }
    
          try
          {
            string idOfLayerWhichIsNotTable = "3";
            fs_db.OpenDataset<Table>(idOfLayerWhichIsNotTable);
          }
          catch (InvalidOperationException)
          {
            // Handle Exception.
          }
        }
      });
    }
    Check if table is versioned
    {
      // Must be called within QueuedTask.Run
      bool IsTableVersioned(Geodatabase geodatabase, string tableName)
      {
        using (Table table = geodatabase.OpenDataset<Table>(tableName))
        {
          // Check table version type
          RegistrationType registrationType = table.GetRegistrationType();
          if (registrationType == RegistrationType.Versioned)
          {
            return true;
          }
        }
        return false;
      }
    }
    Open raster dataset in a geodatabase
    // Create a FileGeodatabaseConnectionPath using the path to the gdb. Note: This can be a path to a .sde file.
    FileGeodatabaseConnectionPath geodatabaseConnectionPath = new(new Uri(@"C:\Temp\rasters.gdb"));
    // Create a new Geodatabase object using the FileGeodatabaseConnectionPath.
    Geodatabase geodatabase = new(geodatabaseConnectionPath);
    // Open the raster dataset.
    RasterDataset gdbRasterDataset = geodatabase.OpenDataset<RasterDataset>("sample");
    Open a Terrain
    {
      //Note: Use QueuedTask.Run to run on the MCT
      string path = @"d:\Data\Terrain\filegdb_Containing_A_Terrain.gdb";
      var fileConnection = new FileGeodatabaseConnectionPath(new Uri(path));
    
      using (Geodatabase dataStore = new Geodatabase(fileConnection))
      {
        string dsName = "nameOfTerrain";
    
        using (var dataset = dataStore.OpenDataset<ArcGIS.Core.Data.Analyst3D.Terrain>(dsName))
        {
        }
      }
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also