Select to view content in your preferred language

How to include a json file in the Add-in

150
1
Jump to solution
04-16-2025 01:16 PM
JinZ
by
Emerging Contributor

I'd like to including a json file to store some setting for the Add-in to read when it's loading. How should I do it? I've added it in the visualstudio solution, when it's compiled it's not ditributed with the add-in. 

0 Kudos
1 Solution

Accepted Solutions
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You need to set your json file's properties (in your project file) to 'Build Action' = 'Content' and 'Copy to Output...' = 'Copy if Newer'

 

jsonProperties.png

Then in your Add-in use the following path to read the json file:

// read the JSON file from the current assembly's executable folder
string asmblyPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string jsonFilePath = System.IO.Path.Combine(asmblyPath, "MyJsonFile.json");
// read the JSON file
string jsonString = System.IO.File.ReadAllText(jsonFilePath);

View solution in original post

1 Reply
Wolf
by Esri Regular Contributor
Esri Regular Contributor

You need to set your json file's properties (in your project file) to 'Build Action' = 'Content' and 'Copy to Output...' = 'Copy if Newer'

 

jsonProperties.png

Then in your Add-in use the following path to read the json file:

// read the JSON file from the current assembly's executable folder
string asmblyPath = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string jsonFilePath = System.IO.Path.Combine(asmblyPath, "MyJsonFile.json");
// read the JSON file
string jsonString = System.IO.File.ReadAllText(jsonFilePath);