There are many methods to obtain the path in c #, which are generally used in the following five ways:
// Obtain the current working directory of the application.
String path1 = System. IO. Directory. GetCurrentDirectory ();
MessageBox. Show ("Get the current working directory of the application:" + path1 );
// Obtain the base Directory of the program.
String path2 = System. AppDomain. CurrentDomain. BaseDirectory;
MessageBox. Show ("Get the program's base Directory:" + path2 );
// Obtain and set the Directory Name of the application.
String path3 = System. AppDomain. CurrentDomain. SetupInformation. ApplicationBase;
MessageBox. Show ("Get and set the name of the directory containing the application:" + path3 );
// Obtain the path of the executable file that started the application, excluding the name of the executable file.
String path4 = System. Windows. Forms. Application. StartupPath;
MessageBox. Show ("Get the path of the executable file that started the application, excluding the executable file name:" + path4 );
// Obtain the path and file name of the executable file that has started the application
String path5 = System. Windows. Forms. Application. ExecutablePath;
MessageBox. Show ("Get the path and file name of the executable file that started the application:" + path5 );