I am developing an extension for ArcGIS 10.3 using ArcObjects in c# and it uses a database (.sdf). I want to setup the extension in such a way that when extension is installed (it is ArcGIS AddIn), it copy the .sdf file from the source folder to the user's folder (common location so that Extension in ArcGIS can access and read from there) in Windows 7.
-
I don't know a way to execute custom action inside the installation process of an AddIn. I would suggest to create a batch or a powershell script that copies your database into the user folder and afterwards starts the AddIn install process. Your customer only needs to run the script instead of double clicking the AddIn. Alternative you can copy the database inside the 'OnStartup()' method if it doesn't exist. But this happens not during the installion but every time the Extension is loaded.– PropperJan 7, 2016 at 8:56
-
Many thanks Propper. Can you provide me a script for AddIn installation and uninstall as I am not good with such scripts. Another question, is it possible to know the path from where the AddIn was installed. I was thinking that if I can track the Path of AddIn installation, I can check inside the code if the database is not at destination location, copy it from the installation folder.– HussainJan 7, 2016 at 15:16
1 Answer
You simply need to modify the following lines and save them into a batch file (for example install.bat).
copy e:\database\myDatabase.sdf %USERPROFILE%\AppData\Roaming\ProgramFolder
The first parameter is the source path of the database. The second parameter is the destination path. %USERPROFILE% stands for the current users home directory. You can modify the subdirectories the way you need. The second line in the batch script is:
start MyAddIn.esriAddIn
Your operating system will know the file extension .esriaddin and start the installation.
For the uninstall you can find an answer here. You can add the described commands in an uninstall.bat and add the following line to delete the database afterwards:
del %USERPROFILE%\AppData\Roaming\ProgramFolder\myDatabase.sdf