Hello,
I have read https://github.com/esri/arcgis-pro-sdk/wiki/ProSnippets-Geodatabase
It looks like there is not snippet to create a GeoDatabase unless it automatically does it if it doesn't exist.
My code is
Geodatabase geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(dbPath)));
This is for opening an existing database, but if dbPath does not exist then how should I approach creating a brand new GeoDatabase?
I have the DirectoryName and the File Name of the geodatabase, so how do I create that?
Thank you!
Solved! Go to Solution.
I found the answer
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
var fGdbPath = file.DirectoryName;
var fGdbName = file.Name;
var fGdbVersion = "Current"; // create the 'latest' version of file Geodatabase
System.Diagnostics.Debug.WriteLine($@"create {fGdbPath} {fGdbName}");
var parameters = Geoprocessing.MakeValueArray
(fGdbPath, fGdbName, fGdbVersion);
var cts = new System.Threading.CancellationTokenSource();
var results = Geoprocessing.ExecuteToolAsync("management.CreateFileGDB", parameters, null, cts.Token,
(eventName, o) =>
{
System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
});
return true;
});
I found the answer
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
var fGdbPath = file.DirectoryName;
var fGdbName = file.Name;
var fGdbVersion = "Current"; // create the 'latest' version of file Geodatabase
System.Diagnostics.Debug.WriteLine($@"create {fGdbPath} {fGdbName}");
var parameters = Geoprocessing.MakeValueArray
(fGdbPath, fGdbName, fGdbVersion);
var cts = new System.Threading.CancellationTokenSource();
var results = Geoprocessing.ExecuteToolAsync("management.CreateFileGDB", parameters, null, cts.Token,
(eventName, o) =>
{
System.Diagnostics.Debug.WriteLine($@"GP event: {eventName}");
});
return true;
});
I found that this name for the tool works as well. Not sure if it has changed or if both will work: CreateFileGDB_management
Static routines on the SchemaBuilder class called CreateGeodatabase and DeleteGeodatabase can also be used to create and delete file geodatabases. Both routines take a FileGeodatabaseConnectionPath as an argument.
It seems easier than Geoprocessing method. It basically only needs two lines of code:
FileGeodatabaseConnectionPath fileGeodatabaseConnectionPath = new FileGeodatabaseConnectionPath(uri);
// Create the file geodatabase
Geodatabase db = SchemaBuilder.CreateGeodatabase(fileGeodatabaseConnectionPath);