ArcGIS Pro 3.5 API Reference Guide
ArcGIS.Desktop.Core Namespace / Project Class / SetDefaultGeoDatabasePath Method
The full path to the geodatabase that will be used
Example

In This Topic
    SetDefaultGeoDatabasePath Method
    In This Topic
    Sets the project's default geodatabase. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SetDefaultGeoDatabasePath( 
       string defaultGeoDatabase
    )
    Public Sub SetDefaultGeoDatabasePath( _
       ByVal defaultGeoDatabase As String _
    ) 

    Parameters

    defaultGeoDatabase
    The full path to the geodatabase that will be used
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    input path cannot be resolved as default geodatabase.
    Remarks

    A project is required to have a default geodatabase. The default geodatabase is used to store spatial datasets and stand-alone tables created by geoprocessing tools. It will also store geodatabase schema items associated with layer templates or schema-only layer packages that are added to a map.

    When a project is created, a file geodatabase (.gdb) is created in the home folder of the new project and set as the project's default geodatabase. Once a project has been created, the default geodatabase can be set to another existing geodatabase; providing the geodatabase has already been added as a geodatabase item to the project. Note that changing the default geodatabase does not move or copy any items from the previous default geodatabase to the new one.

    The ArcGIS Pro application settings may specify a geodatabase that should always be used as the default geodatabase. Anyone using the project is expected to have write access to and appropriate permissions in that geodatabase. If a project uses a file geodatabase as the default geodatabase and the file geodatabase is not available in the specified location, a file geodatabase will be created accordingly to satisfy the default geodatabase path.

    At this time, only file geodatabases can be used as a project's default geodatabase.

    Example
    Change the Project's default gdb path
    string newGDDItemPath = @"C:\path\ArcGIS\Project\NewLocation.gdb";
    string oldGDBItemPath = @"C:\Path\Project\OldLocation.gdb";
    
    //Create a new GDB item and add it to the project
    var newGDBItem = ItemFactory.Instance.Create(newGDDItemPath) as IProjectItem;
    if (newGDBItem == null)
      return;
    var success = Project.Current.AddItem(newGDBItem);
    //make the newly added GDB item the default
    if (success)
      Project.Current.SetDefaultGeoDatabasePath(newGDDItemPath);
    //Now remove the old item
    var oldGDBItem = Project.Current.GetItems<Item>().FirstOrDefault(i => i.Path == oldGDBItemPath) as IProjectItem;
    if (oldGDBItem == null)
      return;
    var removeSuccess = Project.Current.RemoveItem(oldGDBItem);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also