1

I am developing an outlook addin with VSTO for Outlook 2016.

In my deployment, I have a config file which is located in the same directory as the .dll and the .vsto files, aswell as all the other .dll's that are referenced in the addin.

Is it possible at all, to programmatically get the directory, where the .vsto (and my config file) is located. For example the directory where the VSTO would be deployed to could be: "D:\MyPlugins\PluginX\pluginx.vsto"

I tried various constants / methods that would usually work with a "normal" application, i.e:

  • Environment.CurrentDirectory
  • Directory.GetCurrentDirectory()
  • Assembly.Location / Assembly.CodeBase
  • System.Windows.Forms.Application.StartupPath

and while most of them work in debug mode when I start the plugin with Visual Studio, obviously none of them work, because when you install a VSTO, your assembly gets copied to some generated directory.

cmos
  • 482
  • 4
  • 14

2 Answers2

2

CodeBase should always work for the VSTO addins:

    //use CodeBase instead of Location because of Shadow Copy.
    string codebase = Assembly.GetExecutingAssembly().CodeBase;
    var vUri = new UriBuilder(codebase);
    string vPath = Uri.UnescapeDataString(vUri.Path + vUri.Fragment);
    string directory = Path.GetDirectoryName(vPath);
    if (!string.IsNullOrEmpty(vUri.Host)) directory = @"\\" + vUri.Host + directory;
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
1

So turns out, the path I was looking for is the path to the manifest and it is stored in the registry after the VSTO is run.

The manifest path is stored here: {HKEY_CURRENT_USER/HKEY_LOCAL_MACHINE}\Software\Microsoft\Office\{Office application name}\Addins\{add-in ID}\Manifest

cmos
  • 482
  • 4
  • 14