Use an app.config file with an ArcGIS Pro Add-In

4949
13
Jump to solution
03-20-2018 05:51 AM
BillMacPherson
New Contributor III

Has anyone successfully used an app.config file with your Add-In? I have added an app.config file to my visual studio pro SDK project and I’m trying to retrieve a connection string from it. The retrieval code always returns null. I don’t know if that’s because it is a UserControl or running inside ArcGIS Pro or what. Any thoughts? Is there a better place to store the connection string?

 

Visual Studio 2017, .Net Framework 4.6.1, ArcGIS Pro SDK 2.1, SQL Server

 

app.config

 

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

    <connectionStrings> 

        <add name="my_conn" connectionString="Data Source=xx.xx.xx.xxx;Initial Catalog=some_db;User ID=xxx;Password=yyy" /> 

    </connectionStrings>

</configuration>

 

c# code

 

// Assume failure.

string returnValue = null;

 

// Look for the name in the connectionStrings section.

ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["my_conn"];

 

// If found, return the connection string.

if (settings != null)

    returnValue = settings.ConnectionString;

0 Kudos
13 Replies
arunepuri1
New Contributor III

Hi All,

I am using a config.JSON file with ArcGIS Pro to read some user-defined values (like FME workbench paths and it's related input values). Which can be changeable based on user environment and user requirement.

But when I installed this add-in another system, the user will change the .json file according to his local path and values.

How Can make this .json file external exposed and editable by the user.

Please may I know, how to use/Change content in JSON and add-in should read the data from .json.

Thanks,

Arun E

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Your requirements are a bit confusing.  If you really need "user-defined parameters" then Charlie's step-by-step guide is exactly what you need and simple to implement.  Check under this section: https://github.com/Esri/arcgis-pro-sdk/wiki/ProGuide-Custom-settings#step-4-add-a-settingssettings-f...  In essence you use the standard recommended .Net implementation for your user settings (make sure to use user scope).  Below is a summary of the essentials:

User/Application Settings

0 Kudos
MarvisKisakye1
Occasional Contributor

Wolfgang Kaiser‌ I would like to add a new setting of type ArcGIS.Core.Geometry.LinearUnit but it's not available as an option in the settings file designer. Is there a way to add esri types in the .settings file?

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

The easy way is to use the LinearUnit.Wkt property to get the 'well known text' of the linear unit and store the wkt string instead of the LinearUnit type.  At the point of retrieval you can then use CreateLinearUnit with the wkt text as an input parameter.