xxxxxxxxxx
string exePath = AppDomain.CurrentDomain.BaseDirectory;
// returns the directory where the .exe is located
xxxxxxxxxx
string currentDir = System.IO.Directory.GetCurrentDirectory();
//returns the current directory of the application when executing
xxxxxxxxxx
using System.IO;
string currentDirectory = Directory.GetCurrentDirectory();
Console.WriteLine("Current directory: " + currentDirectory);
The resulting output is a message indicating the current directory. Note that the output may vary depending on the location of the application and the user permissions, and that you should use appropriate error handling and validation when working with directories.
xxxxxxxxxx
//Static method returning current directory path ended with default directory separator (different for Windows and Linux)
public static string GetCurrentDir(){
return System.IO.Directory.GetCurrentDirectory()+System.IO.Path.DirectorySeparatorChar;
}