Create or update a table out of selected geodatabase items?

95
3
09-17-2019 08:05 AM
Highlighted
New Contributor

Hi,

I'm trying to create or update a table in a gdb by enabling user to select one or multiple items (eg, feature class, table, ..) from a file geodatabase when a dialog box opens (button addin) in ArcGIS Pro. Therefore, the output table should show feature class or table names, dates, status, username, ...

I'm doing this in C# and here's what I have created so far but it throws an error:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
namespace Geodatabase_FC2Table
{
internal class Btn_OpenGDB : Button
{
protected async override void OnClick()
{
OpenItemDialog CatalogOpenDialog = new OpenItemDialog()
{
Title = "Select Geodatabases",
MultiSelect = true,
Filter = ItemFilters.geodatabaseItems_all
};

GeoDatabaseReader geoDbReader = new GeoDatabaseReader();
List<LayerObjectInfo> resultArr = new List<LayerObjectInfo>();
if (CatalogOpenDialog.ShowDialog() == true)
{
foreach (Item item in CatalogOpenDialog.Items)
{
List<LayerObjectInfo> aGdbResultArr = await geoDbReader.ReadGeoDataBase(item.Name);
resultArr.AddRange(aGdbResultArr);
MessageBox.Show(item.Name);

}
}
}
}
public class GeoDatabaseReader
{
public async Task<List<LayerObjectInfo>> ReadGeoDataBase(string GeoDataBasePath)
{
List<LayerObjectInfo> result = new List<LayerObjectInfo>();
await QueuedTask.Run(() =>
{
var path = new Uri(GeoDataBasePath);
var gdb = new Geodatabase(new FileGeodatabaseConnectionPath(path));
IReadOnlyList<FeatureClassDefinition> definitions = gdb.GetDefinitions<FeatureClassDefinition>();

foreach (var fdsDef in definitions)
{
LayerObjectInfo layerObjectInfo = new LayerObjectInfo();
TableDefinition ATableDef = fdsDef as TableDefinition;
layerObjectInfo.LayerName = (string.IsNullOrEmpty(ATableDef.GetAliasName())) ? ATableDef.GetName() : ATableDef.GetAliasName();
DateTime today = DateTime.Today;
layerObjectInfo.Date = today;
layerObjectInfo.UserName = Environment.UserName;
layerObjectInfo.Status = "Complete";
result.Add(layerObjectInfo);
}
});
return result;
}
}
public class LayerObjectInfo
{
public string LayerName { get; set; }
public string Date { get; set; }
public string UserName { get; set; }
public string Status { get; set; }
}
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Thank you.

Tags (2)
Reply
0 Kudos
3 Replies
Highlighted
Esri Regular Contributor

Steve,

Do you what error is being returned and what line is failing?

--Rich

Reply
0 Kudos
Highlighted
New Contributor

Hi Rich,

when I run the code I get this error:

Reply
0 Kudos
Highlighted
Esri Contributor

Hi Steve,

Next step is , add the breakpoint at that line .

And debug it.

When Breakpoint hit.

Open the immediate windows in visual studio Ctrl+Alt+I

Check your geodatabasepath variable in it whether it is valid path or not.

Reply
0 Kudos