AnsweredAssumed Answered

Create or update a table out of selected geodatabase items?

Question asked by Steve11jackson on Sep 17, 2019
Latest reply on Sep 17, 2019 by taungesriaustralia-com-au-esridist

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.

Outcomes