Summary of the Method Example of Obtaining File Path by Winform in C
- 2021-08-12 03:21:34
- OfStack
In this paper, the method of obtaining file path by Winform in C # is described as an example. Share it for your reference. The details are as follows:
Get the filename method:
Methods with System. IO. Path. GetFileName and System. IO. Path. GetFileNameWithoutExtension (without extension)
Get the file path method:
// Gets the full path of the current process, including the file name ( Process name ) .
string str = this.GetType().Assembly.Location;
result: X:\xxx\xxx\xxx.exe //(.exe Directory where the file is located +.exe Filename )
// Gets the new Process Component and associates it with the current active process, including the file name ( Process name ) .
string str = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
result: X:\xxx\xxx\xxx.exe //(.exe Directory where the file is located +.exe Filename )
// Gets and sets the fully qualified path to the current directory (that is, the directory from which the process started).
string str = System.Environment.CurrentDirectory;
result: X:\xxx\xxx //(.exe Directory where the file is located )
// Gets the current Thread The base directory of the current application domain of, which is used by the assembly resolver to probe assemblies.
string str = System.AppDomain.CurrentDomain.BaseDirectory;
result: X:\xxx\xxx\ //(.exe Directory where the file is located +"\")
// Gets and sets the name of the directory containing the application.
string str = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
result: X:\xxx\xxx\ //(.exe Directory where the file is located +"\")
// Gets the path of the executable file that started the application, excluding the name of the executable file.
string str = System.Windows.Forms.Application.StartupPath;
result: X:\xxx\xxx //(.exe Directory where the file is located )
// Gets the path of the executable file that started the application, including the name of the executable file.
string str = System.Windows.Forms.Application.ExecutablePath;
result: X:\xxx\xxx\xxx.exe //(.exe Directory where the file is located +.exe Filename )
// Gets the current working directory of the application ( Unreliable ) .
string str = System.IO.Directory.GetCurrentDirectory();
result: X:\xxx\xxx //(.exe Directory where the file is located )
I hope this article is helpful to everyone's C # programming.