1

Can anyone tell me what's the difference between System.CurrentDomain.AppDomain.BaseDirectory and Directory.GetCurrentDirectory() in C#, please??

See AppDomain on MSDN and also Directory.GetCurrentDirectory() on MSDN.

stuartd
  • 70,509
  • 14
  • 132
  • 163
FranzHuber23
  • 3,311
  • 5
  • 24
  • 63
  • As editing is not working: "Hello community" in front of this is missing :/ – FranzHuber23 Mar 18 '16 at 16:22
  • [Salutations are not required..](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts) – stuartd Mar 18 '16 at 16:26
  • Ok, didn't know about this one. – FranzHuber23 Mar 18 '16 at 18:58
  • "Difference" in what way? They are completely different parts of the API. The values will often, but not always, be the same. The current "working" directory (returned by `GetCurrentDirectory()`) can be changed, either when you start a process or from within. Please explain your question: what difference are you expecting and/or concerned about that isn't already adequately described by the documentation? – Peter Duniho Mar 18 '16 at 23:03
  • Ok, so then my question would be: "When are those 2 not exactly the same?" – FranzHuber23 Mar 23 '16 at 15:26

1 Answers1

0

According to this question the difference is that

System.AppDomain.CurrentDomain.BaseDirectory returns current directory, not executable location, i.e. when run from outlook (sent as a link to \server\folder\file.exe it will set BaseDirectory to user documents instead executable location from Jakub Pawlinski whereas Directory.GetParent(Assembly.GetExecutingAssembly().Location) gets the parent folder of the current execting assembly.

So the code I'm using now is:

string location = Assembly.GetExecutingAssembly().Location;
if (location != null)
{
    string config = Path.Combine(Directory.GetParent(location).FullName, "Config.xml"));
}
Community
  • 1
  • 1
FranzHuber23
  • 3,311
  • 5
  • 24
  • 63