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

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

    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 file-system data store has been opened prior to calling this operation.

    -or-

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

    name is null or an empty string.
    A geodatabase-related exception has occurred. For example, the name is invalid.
    Example
    Opening a FeatureClass from a ShapeFile Datastore
    public async Task OpenShapefileFeatureClass()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        FileSystemConnectionPath fileConnection = new FileSystemConnectionPath(new Uri("path\\to\\folder\\containing\\shapefiles"), FileSystemDatastoreType.Shapefile);
        using (FileSystemDatastore shapefile = new FileSystemDatastore(fileConnection))
        {
          FeatureClass taxLotsFeatureClass = shapefile.OpenDataset<FeatureClass>("TaxLots");
          FeatureClass manHolesFeatureClass = shapefile.OpenDataset<FeatureClass>("ManHoles.shp"); // Can use the .shp extension, but its not needed.
          Table taxDetailsTableWithoutExtension = shapefile.OpenDataset<Table>("TaxDetails");
          Table taxDetailsTable = shapefile.OpenDataset<Table>("TaxDetails.dbf");
        }
      });
    }
    Opening a CAD Datastore
    public async Task OpenCADFeatureClass()
    {
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        FileSystemConnectionPath fileConnection = new FileSystemConnectionPath(new Uri("path\\to\\folder\\containing\\CAD"), FileSystemDatastoreType.Cad);
        using (FileSystemDatastore cadDatastore = new FileSystemDatastore(fileConnection))
        {
          // note - extension is required
          FeatureClass cadDataset = cadDatastore.OpenDataset<FeatureClass>("hatchplayboundaries.dwg");
          // take note of the pattern for referencing a feature class. 
          FeatureClass cadfeatureClass = cadDatastore.OpenDataset<FeatureClass>("hatchplayboundaries.dwg:Polyline");
    
          int numRows = 0;
          using (RowCursor cursor = cadfeatureClass.Search())
          {
            while (cursor.MoveNext())
              numRows++;
          }
        }
      });
    }
    Open raster dataset in a folder
    // Create a FileSystemConnectionPath using the folder path.
    FileSystemConnectionPath connectionPath = new FileSystemConnectionPath(new System.Uri(@"C:\Temp"), FileSystemDatastoreType.Raster);
    // Create a new FileSystemDatastore using the FileSystemConnectionPath.
    FileSystemDatastore dataStore = new FileSystemDatastore(connectionPath);
    // Open the raster dataset.
    RasterDataset fileRasterDataset = dataStore.OpenDataset<RasterDataset>("Sample.tif");
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also