Select to view content in your preferred language

Embedding data in an esriAddIn

1198
5
07-27-2010 01:04 PM
phenderson
Emerging Contributor
The ArcObjects documentation under "Advanced add-in concepts" states:

You can create additional folders and files under the Install folder. This is useful in cases where you want to ship data as part of your add-in.

Can anyone provide details or a complete example how to do this?

Thanks.
0 Kudos
5 Replies
GroundHogg
Emerging Contributor
The ArcObjects documentation under "Advanced add-in concepts" states:

You can create additional folders and files under the Install folder. This is useful in cases where you want to ship data as part of your add-in.

Can anyone provide details or a complete example how to do this?

Thanks.



Not exactly what you want, but if you only needed a few paths that can be changed by the user and stored (application settings),  If you are using VB.net you can use the My.settings property of VB.net.  It stores values in an xml, in this case its the app.config which goes with the add-in.

in Visual Studio, go to the Project Properties page:

Project-> Properties-> Settings

here you can add any values you want as names with a choice of string, integer, etc.


make a variable, say "user_name", string

you access them like this:

My.Settings.user_name = "Ground Hogg"

dim pName = My.Settings.user_name

save settings with

My.Settings.save()

I'm using about 10 in my project, all strings to hold paths to data sets.  Seems to be working just fine for my Button "add-In", but I have not distributed it yet.

Sadly, Ive read it doesn't work for C#.


edited: misread original question, not a solution for the original post.
0 Kudos
EagerIp
Deactivated User
If you are writing .NET add-in projects, the options for retrieving application related data/configuration files should be similar to any regular .NET projects.

First option si to add the data files to your project and mark their "Copy To Output Directory" property to "Copy Always" so the build process will copy the files to the build output folder (i.e. where your assembly output is). In your code, you can use the relative path to the add-in assembly to access the files.

Another option is to use embedded resource.

Note that these two options above are mainly for shipping "static" data files alongside with your add-in. If you need to retrieve/store user settings, you should consider writing the files to an appropriate AppData folder.
0 Kudos
RandyHauser
Occasional Contributor
So what's the correct way to reference an included file? In my project I have a config folder and inside of it a config.xml file with some settings in it. The xml file is set to Copy Always to the output directory, and if I unzip the resulting .esriAddIn I can see the folder and the file.

If I try to reference the file as "config/config.xml", I get an error at runtime because VB is looking for the file relative to the ArcGIS bin directory, not the add-in. Is there some way to reference the location in the add-in, especially since it's a zip and might be all in memory?
0 Kudos
JeffreyHamblin
Occasional Contributor
There was another thread about this. You need to get the directory of the AddIn assembly. Check the last post and see if it helps:

http://forums.arcgis.com/threads/17397-Add-In-embedded-Files-and-use-it-s-path

-Jeff
0 Kudos
RandyHauser
Occasional Contributor
Thanks, found it right before you posted.

Also see this Stack Overflow thread:

http://stackoverflow.com/questions/52797/c-how-do-i-get-the-path-of-the-assembly-the-code-is-in
0 Kudos