7

I see that my add-ins are installed to C:\Users\Me\AppData\Local\ESRI\Desktop10.0\AssemblyCache{6C90269B-D233-4122-3747-C2AE1131E22C}

Is it possible to find that file path from within the Add-in itself? e.g., someone would click a button and it would tell them the path where the add-in is located.

I want to use this location to store user-defined configuration info.

5
  • won't let me post my own answer yet, so here it is: This returns full path to the .dll Public Function FindMe() As String FindMe = System.Reflection.Assembly.GetExecutingAssembly().Location ' MsgBox(FindMe) return FindMe End Function
    – user4979
    Commented Nov 30, 2011 at 19:04
  • 3
    You might consider creating a well-known folder under %APPDATA% to store user configuration data rather than in the AssemblyCache folder as this is subject to deletion by the add-in framework and as you have seen requires reflection to determine.
    – blah238
    Commented Nov 30, 2011 at 20:30
  • 1
    @user4979: you might want to check out this question if you are looking at adding user scoped settings: gis.stackexchange.com/questions/9001/… Commented Nov 30, 2011 at 21:51
  • @blah238 user4979 has not been seen here for over 3 years, and I do not have the knowledge to translate their (and/or your) comment into an answer. Could you perhaps do so sometime?
    – PolyGeo
    Commented Feb 15, 2015 at 1:46
  • @PolyGeo It was not an answer, just a suggestion.
    – blah238
    Commented Feb 15, 2015 at 15:01

2 Answers 2

3

Here is the C# code to get the addin assembly folder:

public static string AssemblyDirectory
        {
            get
            {
                string codeBase = Assembly.GetExecutingAssembly().CodeBase;
                UriBuilder uri = new UriBuilder(codeBase);
                string path = Uri.UnescapeDataString(uri.Path);
                return Path.GetDirectoryName(path);
            }
        }

and VB.NET:

Public Shared ReadOnly Property AssemblyDirectory() As String
    Get
        Dim codeBase As String = Assembly.GetExecutingAssembly().CodeBase
        Dim uri__1 As New UriBuilder(codeBase)
        Dim path__2 As String = Uri.UnescapeDataString(uri__1.Path)
        Return Path.GetDirectoryName(path__2)
    End Get
End Property
0

If you are using Python, you can find the folder location by doing the following

import os
print os.path.dirname(__file__)
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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