Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm in the process of converting an older ArcMap extension to an Add-In in C# and I am trying to best take advantage of the XML based configuration.

Config.esriaddinx works great for the basic set up (toolbar, buttons, extension info, etc), but is there a way to add other configuration parameters, such as field names, layer names, database connections, etc?

Would I need to create an App.config file? If so, would the App.config file still be packaged/deployed the same as the rest of the add-in? What would be the best method to read the parameters? I am a newbie to add-ins and any suggestions or samples would be greatly appreciated. Thanks!

share|improve this question
add comment

2 Answers

First off, I have not tried using Config.esriaddinx for this purpose, but I wouldn't recommend it. It is meant for the configuration of the add-in itself, not necessarily user data, and you probably don't want to mix the two.

It has been a while since I've dealt with this myself so I may be a little fuzzy on the details, but there are multiple issues with using configuration files in ArcGIS add-ins: ESRI ArcMap Add-in with app.settings not recognizing app.config changes

In particular, the directory the add-in is extracted to is overwritten each time the application is started, so you can't really persist changes to settings there. If your settings never change or only change with each new version of your add-in then this is probably not a concern.

If, however, you want to make your add-in configurable by the end user then you need to store the user-configurable information elsewhere so they aren't overwritten. I would suggest using the user's Application Data folder, whose path you can determine programmatically like so:

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

I would also suggest putting it in a subfolder named after your add-in. But essentially you would be loading from and saving to a file in that location instead of reading settings from your add-in's Settings class or the configuration file in the add-in's directory. If you want to use .NET configuration for this then I suggest reading up on Application Settings and ConfigurationManager.

The other problem I have had is with using custom configuration sections when using .NET configuration. Using Assembly.LoadFrom and handling the AssemblyResolve event was the solution to that particular problem, although in that case I ended up not using .NET configuration for that and other reasons.

Depending on the complexity of your configuration scenario, you could, like I did, eschew using the .NET configuration system entirely and instead use some other method of reading and writing configuration information. I ended up using SerializableAttribute-marked classes or classes which implemented IXmlSerializable for this purpose in one of the more complex add-ins I created which included user-configurable settings such as lists of layers, connection settings, etc. I would recommend reading Object Serialization in .NET, Introducing XML Serialization and How to Implement IXmlSerializable Correctly if you are interested in that approach.

It sounds like yours is along the same lines so it is up to you, but I found the XML serialization approach to be preferable to .NET configuration for all but the simplest of configuration scenarios (simple data types, no hierarchies/collections).

share|improve this answer
    
Great info here, @blah238! I'll expore these options and see what will work best. –  petegis Apr 19 '13 at 16:42
    
How do you deploy the xml file to the Environment.SpecialFolder.ApplicationData folder when you distribute the addin file to your users? Is it a case of manually copy/pasting the file? –  Vidar Feb 12 at 17:35
add comment

Create a config.xml file and set it's build action to AddInContent under the VS properties for the file.

To add to this based on the comment, since you are doing it in C# I was assuming you are using Visual Studio to author your addin. From there if you add an XML configuration file from the file new option and name it config.xml it will create a default empty file. From there you can specify key value xml settings under the appSettings tag the same as a normal xml configuration file and then refer to these from code as you normally would. To change it's build action, when you have the file selected in VS, look at the properties window and there should be a build action setting. Select this and it will show a drop down of the available options, choose AddInContent from the list.

share|improve this answer
1  
Welcome to GISse. This is a very brief answer. It would help to include some more detail, perhaps incorporating some of the details that @petegis mentioned, like how to add particular parameters to this file. Also, how would you go about creating this file? Is it done through ArcMap, or in a text editor? What is the proper structure? Think about if you had never created one before, what would you need to know in order to successfully do so. That sort of information will make for a superb answer. Good start! –  Get Spatial Apr 19 '13 at 0:38
    
Thanks @davetimmins. Seems straightforward enough, I gave this a shot and it works as long as the file is not actually named "config.xml" (throws a build error "Cannot create a file when that file already exists"). –  petegis Apr 19 '13 at 16:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.