0

I'm trying to resolve the current folder for dot net console app, it needs to be read on app init.

  • 1
    Duplicate shows all sorts of answers to all variations of the question you may mean. If none actually answers your specific question - please [edit] this question to be very clear of what you need to achieve and how all variations in the linked duplicate did not work. – Alexei Levenkov Jul 18 '21 at 06:02
  • The current directory may well be different from the directory where the executable is located. If you need the latter, you could use Assembly.Location, Assembly.CodeBase or AppDomain.BaseDirectory (which are all slightly different). – Klaus Gütter Jul 18 '21 at 06:20
  • This question is actually clear, whether intended or not, while the linked question has a wrong title, and is not a duplicate of this question. This question should therefore not have been closed with the given reason. The fact that the linked question has some wrong answers that is the answer to this question, should not count against this conclusion. – Bent Tranberg Jul 18 '21 at 06:35

2 Answers2

0

For console app you just need to use

Directory.GetCurrentDirectory() + "/YOUR_DIR_NAME";

So you can get the current path relative to where the app is started.

alydemah
  • 49
  • 1
  • 6
  • 1
    Do not use string concatenation to build paths, use Path.Combine; it respects the host system directory separator char – Caius Jard Jul 18 '21 at 06:05
-1

You can use Environment.CurrentDirectory

Caius Jard
  • 72,509
  • 5
  • 49
  • 80