8

In my program, I need to copy a template database from the default location, which I understand will be different depending on the installer I choose to use. The problem is that I can't seem to read the actual path of |DataDirectory| I understand that I should use AppDomain.CurrentDomain.GetData("DataDirectory") but it always returns Null in debugger which means I can't test my code. I've tried the following two syntaxes:

string sourcePath = AppDomain.CurrentDomain.GetData("DataDirectory").ToString();

and

string defaultpath = Convert.ToString(AppDomain.CurrentDomain.GetData("DataDirectory"));

Am I doing something wrong?

ThanX!

PAUL DUFRESNE
  • 348
  • 3
  • 4
  • 11

1 Answers1

10

Try with APPBASE

AppDomain.CurrentDomain.GetData("APPBASE")

http://msdn.microsoft.com/en-us/library/system.appdomainsetup.applicationbase.aspx

If you want DataDirectory key you must execute before SetData

Aghilas Yakoub
  • 28,516
  • 5
  • 46
  • 51
  • 1
    Thank you. Just to confirm, as I understand it the database could be stored in different locations based on how it's packaged. I understand debug puts it in the app folder, but that if it's deployed as with ClickOnce the database could be in a sub-folder and that MSI does something else completely. – PAUL DUFRESNE Sep 05 '12 at 19:46
  • 2
    What does this have to do with |DataDirectory| ? – monstro Aug 17 '18 at 15:22
  • For me, that's null too. – NickG Jun 18 '20 at 12:07