ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Catalog Namespace / GDBProjectItem Class / GetDatastore Method
Example

In This Topic
    GetDatastore Method (GDBProjectItem)
    In This Topic
    Gets the ArcGIS.Core.Data.Datastore associated with the workspace corresponding to ArcGIS.Desktop.Core.Item.Path. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public Datastore GetDatastore()
    Public Function GetDatastore() As Datastore

    Return Value

    A specific ArcGIS.Core.Data.Datastore (e.g., ArcGIS.Core.Data.Geodatabase) associated with the workspace corresponding to ArcGIS.Desktop.Core.Item.Path. If the workspace is not currently supported, an instance of ArcGIS.Core.Data.UnknownDatastore is returned.
    Exceptions
    ExceptionDescription
    The type of data store corresponding to ArcGIS.Desktop.Core.Item.Path is invalid.
    If the path to the data store is invalid or the data store cannot be opened or currently not supported.
    A geodatabase-related exception has occurred.
    This method or property must be called within the lambda passed to QueuedTask.Run
    Example
    Obtaining Geodatabase from Project Item
    public async Task ObtainingGeodatabaseFromProjectItem()
    {
      IEnumerable<GDBProjectItem> gdbProjectItems = Project.Current.GetItems<GDBProjectItem>();
    
      await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
      {
        foreach (GDBProjectItem gdbProjectItem in gdbProjectItems)
        {
          using (Datastore datastore = gdbProjectItem.GetDatastore())
          {
            //Unsupported datastores (non File GDB and non Enterprise GDB) will be of type UnknownDatastore
            if (datastore is UnknownDatastore)
              continue;
    
            Geodatabase geodatabase = datastore as Geodatabase;
            // Use the geodatabase.
          }
        }
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also