Create new GeoDatabase with ArcGIS Pro SDK

473
3
Jump to solution
07-25-2019 10:19 AM
JamesKennedy1
New Contributor III

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!

0 Kudos
1 Solution

Accepted Solutions
JamesKennedy1
New Contributor III

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;
});

View solution in original post

3 Replies
JamesKennedy1
New Contributor III

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;
});

View solution in original post

LesleyBross1
New Contributor III

I found that this name for the tool works as well. Not sure if it has changed or if both will work: CreateFileGDB_management

0 Kudos
nicogis
MVP Frequent Contributor
0 Kudos