title: What's the best way to get the directory from which an assembly is executing
body: <p>For my apps, I store some configuration file in xml along with the assembly(exe), and something other temporary files for proccessing purpose.  </p>
  
  <p>I found some quirk with <code>".\\"</code> and <code>Application.StartupPath</code>.</p>
  
  <p>I've been using </p>
  
  <pre><code>String configPath = ".\\config.xml";
  </code></pre>
  
  <p>It works fine until I called <code>OpenFIleDialog</code> to open some files in other folders, the statement above failed. Apparently ".\" is referring to "CurrentDirectory", which changes every time when we browse to another folder.</p>
  
  <p>At some point, I was using </p>
  
  <pre><code>String configPath = Path.Combine(Application.StartupPath + "config.xml");
  </code></pre>
  
  <p>At some point, when I need to execute this assembly from another folder by using <code>Process.Start()</code>, things start to fall apart. Apparently the working directory is not set properly, and <code>Application.StartupPath</code> is actually referring to working directory instead of the directory of which the assembly is executing, as I've assumed. So I have to resort to using ProcessInfo to setup the working directory to the assembly's directory. I also had problem with this when I was writing VSTO.</p>
  
  <p>So, my question is, what's the best, simplest and most assured way to get the current directory that the assembly is executing, without those quirks(or misunderstanding) that I've just mentioned?</p>
  
  <p>EDIT: I meant to get the directory which the assembly reside</p>
  
  <p>EDIT: According to MSDN on <a href="http://msdn.microsoft.com/en-us/library/system.appdomain.basedirectory.aspx" rel="noreferrer">AppDomain.BaseDirectory</a>, it seems that it can be changes during runtime, which is what I don't want(Just to clarify, not that I don't want to allow changing BaseDirectory, but rather, when I retrieve it without knowing for sure whether it's been changed)</p>
  
  <p>EDIT: I've notice that a related question was posted much earlier. <a href="https://stackoverflow.com/questions/158219/what-would-cause-the-current-directory-of-an-executing-app-to-change">What would cause the current directory of an executing app to change?</a></p>
  
  <p>Thanks guys for the answer.</p>