Search code examples
c#app-configexcel-dnaworking-directory

CurrentDirectory and Excel-DNA


I'm using Excel-DNA and debbuging a c# code that is used in Excel by attaching the process to VS17.

My issue is that i don't understand why while debugging, my project's current directory switches to C:\Users\userX\Documents:

string test = Directory.GetCurrentDirectory(); // C:\Users\userX\Documents

which is a directory not used at all in all the classes in my project and poses an issue as i'm using an app.Config to read some static data (which hence won't be retrieved):

string staticData = ConfigurationManager.AppSettings["data"];

I'm wondering how i could overcome this issue ?

Many thanks for your help.


Solution

  • It's Excel setting the current directory.

    You can retrieve the full path to your Excel-DNA add-in with a call to ExcelDnaUtil.XllPath.