Skip to content

ProSnippets CoreHost

arcgisprosdk edited this page Sep 4, 2015 · 22 revisions
Language:      C#
Subject:       CoreHost
Contributor:   ArcGIS Pro SDK Team <[email protected]>
Organization:  Esri, http://www.esri.com
Date:          7/13/2015
ArcGIS Pro:    ArcGIS Pro 1.1
Visual Studio: 2013, 2015

##Initializing Core Host

using ArcGIS.Core.Data;
//There must be a reference to ArcGIS.CoreHost.dll
using ArcGIS.Core.Hosting;

class Program {
    //[STAThread] must be present on the Application entry point
    [STAThread]
    static void Main(string[] args) {

        //Call Host.Initialize before constructing any objects from ArcGIS.Core
        try {
            Host.Initialize();
        }
        catch (Exception e) {
            // Error (missing installation, no license, 64 bit mismatch, etc.)
            Console.WriteLine(string.Format("Initialization failed: {0}",e.Message));
            return;
        }

        //if we are here, ArcGIS.Core is successfully initialized
        Geodatabase gdb = new Geodatabase(@"C:\Data\SDK\GDB\MySampleData.gdb");
        IReadOnlyList<TableDefinition> definitions = gdb.GetDefinitions<FeatureClassDefinition>();

        foreach (var fdsDef in definitions) {
            Console.WriteLine(TableString(fdsDef as TableDefinition));
        }
        Console.Read();
    }

    private static string TableString(TableDefinition table) {
        string alias = table.GetAliasName();
        string name = table.GetName();
        return string.Format("{0} ({1})", alias.Length > 0 ? alias : name, name);
    }

}

Home

ProSnippets: CoreHost

Clone this wiki locally