0

I am currently working on a VSTO Add In for Outlook. I have created an additional .json file to store some data that I added to my project folder in Visual Studio. My problem is, that this file does not show up in the Assembly directory, so I can only access it via the static filepath to the project directory. As I want to deploy and distribute the Add In I figured that this is something I want to avoid, as the json should locally store some data for each Add In user.

I tried to change the properties of the file such that it is copied to the output directory and that the content is built. However, I still don`t see the file in the

Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)

directory. So my question is whether I am doing something wrong or if there is a better way to distribute files with the Add In.

Many thanks in advance and best regards!

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
Jonas
  • 43
  • 4

1 Answers1

0

You may use the following code instead:

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);
    }
}

See How do I get the path of the assembly the code is in? for alternatives ways of retrieving the current folder.

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45