SoFunction
Updated on 2025-03-06

Summary of the example method of Winform obtaining file path in C#

This article describes the method of Winform obtaining file paths in C#. Share it for your reference. The details are as follows:

How to get file name:

Methods with and (no extension)

How to get file path:

//Get the full path of the current process, including the file name (process name).string str = ().;
result: X:\xxx\xxx\ //(The directory where the .exe file is located +.exe file name)
//Get the full path of the main module to obtain the new Process component and associate it with the currently active process, including the file name (process name).string str = ().;
result: X:\xxx\xxx\ //(The directory where the .exe file is located +.exe file name)
//Get and set the fully qualified path to the current directory (i.e. the directory from which the process starts).string str = ;
result: X:\xxx\xxx //(The directory where the .exe file is located)
//Get the base directory of the current application domain of the current Thread, which is used by the assembly conflict resolver to detect the assembly.string str = ;
result: X:\xxx\xxx\ //(The directory where the .exe file is located + "\")
//Get and set the name of the directory containing the application.string str = ;
result: X:\xxx\xxx\ //(The directory where the .exe file is located + "\")
//Get the path to the executable file that started the application, excluding the name of the executable file.string str = ;
result: X:\xxx\xxx //(The directory where the .exe file is located)
//Get the path to the executable file that started the application, including the name of the executable file.string str = ;
result: X:\xxx\xxx\ //(The directory where the .exe file is located +.exe file name)
//Get the application's current working directory (unreliable).string str = ();
result: X:\xxx\xxx //(The directory where the .exe file is located)

I hope this article will be helpful to everyone's C# programming.