Adding an Add-In Folder programmatically

2693
8
09-29-2011 03:31 AM
ChrisPouliot
New Contributor III
Hello,

I'm looking for a way to programmatically add an Add-In folder to the list in the Add-In Manager of ArcMap.  I have tried simply adding the folder path to the AddInFoldersList.xml file in my AppData\Local\ESRI\Desktop10.0 folder but that doesn't work because when ArcMap closes it overwrites that file and removes my changes.

Any help would be appreciated.

Thanks!

Chris
Reply
0 Kudos
8 Replies
MichaelRobb
Regular Contributor II
Hello,

I'm looking for a way to programmatically add an Add-In folder to the list in the Add-In Manager of ArcMap.  I have tried simply adding the folder path to the AddInFoldersList.xml file in my AppData\Local\ESRI\Desktop10.0 folder but that doesn't work because when ArcMap closes it overwrites that file and removes my changes.

Any help would be appreciated.

Thanks!


Chris


I have no problem doing it this way. Arc does write to the XML during close, but if you have added the folder path and the esriaddinx files are there, nothing will change.  Unless... perhaps the folder path you are inserting no longer exists when arc is closing.

I had written an exe which, pending windows version (xp, win 7) will enable OFFLINE MODE which prevents the loss of the link as well.  (IF the folder is on a server) the second you unplug connection, lets say for a laptop, all the tools are removed during next ARC initialize.

I would confirm in Addin Manager >> options that the folder path does indeed exist before closing.
Perhaps a mistake was made in the xml file.

Recap:
1. verify xml is correct (verifying under options that the folder path and SHARED addins exist before closing Arc) - its possible IF the path (desired folder) contains NO addins, would be removed as well, but I dont know on that)
2. verify folder connection is not lost.
Reply
0 Kudos
ChrisPouliot
New Contributor III
Thanks for the response Mike.

To recreate my issue try the following:

1. Open ArcMap
2. Open the AddInFoldersList.xml and add an entry to a valid path containing an esriaddinx file.  Save the file.
3. Close ArcMap.
4. Open the AddInfoldersList.xml file.  The changes I made in step #2 are gone.

I'm not sure what I'd be doing differently than you.

I've reported this to ESRI Support and their response is that the inability to edit the Add-In folders list in ArcMap using ArcObjects is a bug and will be added to their fixit pile.
Reply
0 Kudos
MichaelRobb
Regular Contributor II
Step 1 is your problem.

Why do you have Arc open when modifying the settings? Of course arc will save to the xml (based on what is in Addin Manager) which would be nothing in this case, hence why your xml modification is gone.  You need to give the settings PRIOR so the active session establishes those changes.  I mention in my prior post...
"I would confirm in Addin Manager >> options that the folder path does indeed exist before closing."
meaning, under Customize >> Addin-Manager >> Options >> folders ... you would have noticed it would be empty.  This is becuase Arc will ONLY read this xml file during Startup (initialization)

The settings must be established prior to opening a session.
Just like re-arranging your toolbars, buttons and customization, is saved on Shut down. (to the normal.mxt)... so empty add-in folder options (in the arc session) = will save the default xml string to the AddInFoldersList.xml.  Arc does not look at that file DURING an open session, only on start up, and saves the information (contained in that arc session) on shutdown.

You could, open arc first, then modify the xml, open ANOTHER arc session, see the changes, close that one down, xml will keep the changes (as it saves them), then close the First Arc (which contains no folder settings), and your xml folder will be over-written with no folder path. (hope that is not confusing)


Hope that makes sense.


There is no bug, not sure why ESRI would say that.

Recap:
You should modify the xml as step 1.  That is it! 
Open Arc, you will see the folder in Addin Manager... when you close, it will re-write what you told Arc back to the xml as usual.

You should also, just ensure you are up to date with the Build 3200 level (service pack 2) and have the ten patches installed.  (up to _34 in regkeys)
Reply
0 Kudos
ChrisPouliot
New Contributor III
The problem is that I want to make these edits from within a custom ArcMap add-in, therefore, Arcmap would be running at the time.  ArcObjects gives me the ability to programmatically add a Toolbox, modify toolbars, do pretty much anything with code from within a running ArcMap session.  I can't, however, add an add-in folder to the Add-in folder list on the fly.  This would be ideal and it is what ESRI is hopefully changing.

I'm leaning toward doing something in ArcMap's OnShutdown event to get that XML file written correctly.
Reply
0 Kudos
MichaelRobb
Regular Contributor II
The problem is that I want to make these edits from within a custom ArcMap add-in, therefore, Arcmap would be running at the time.  ArcObjects gives me the ability to programmatically add a Toolbox, modify toolbars, do pretty much anything with code from within a running ArcMap session.  I can't, however, add an add-in folder to the Add-in folder list on the fly.  This would be ideal and it is what ESRI is hopefully changing.

I'm leaning toward doing something in ArcMap's OnShutdown event to get that XML file written correctly.


If you can find a way to modify that options box during a session, you would be set. (modifying the xml will not do, as you know now)  its not a bug though, and that is what ESRI would have to change if they want to, give you access to that Options box via objects...
They will not be able to change the read and write sequence of the xml file. (as it works logically as is). Not sure how long you want to wait either.

I am not sure if you will be able to write onshutdown after arc's embedded xml overwrite takes place...
I wrote an exe as its a one time deal, all workstations will always point at one folder on a secure server for all addins.  Is there a reason why the adjustments must be made in an addin. (just something to think about).

Either way. good luck.
Reply
0 Kudos
ChrisPouliot
New Contributor III
Thanks for all the input.

We have an install BAT file for ArcGIS that includes a registry entry defining one location of our Add-Ins on our V:\.  On there we have an add-in called Quick Layers that is an interface for accessing our data stores.  The data stores contain data as well as applications (Add-Ins) in a well defined hierarchy.  The user has the ability to define the locations of these data stores (one or many).  When they specify the data location Quick Layers will then set Add-In folders based on the data store location they defined.  It saves our users the additional step of managing their locations in the Add-In Manager.  With well over 500 users in our agency the easier we can make it the fewer support calls we get.

I'll get it straightened out but I appreciate being able to bounce ideas off other professionals.  Thanks!
Reply
0 Kudos
MichaelRobb
Regular Contributor II
You know, you could, make the xml file READ ONLY once your addin has altered it and saved it.  When Arc Closes, your new xml file would remain (arc doesn't have a hissy fit over it), and the next open would see the changes.

It might work!

Just have some code

 Dim attribute as System.IO.FileAttributes = FileAttributes.ReadOnly
File.SetAttributes("Location\AddinFoldersList.xml", attribute


You get the idea.
Reply
0 Kudos
ChrisPouliot
New Contributor III
That's exactly what ESRI Support suggested.  The problem with that is that the user is then unable to specify any of their own Add-In folders.  Well, they can, but they won't be saved out to the XML file.
Reply
0 Kudos