How to get the current working folder in C#
By FoxLearn 11/13/2024 4:07:13 PM 90
In C#, you can get the current working directory using the Directory.GetCurrentDirectory() method, which is part of the System.IO namespace.
How to get the current working folder in C#?
You can use the static `Directory` class in C# to get the current working directory with `Directory.GetCurrentDirectory()`.
string currentDirectory = System.IO.Directory.GetCurrentDirectory(); Console.WriteLine("Current working directory: " + currentDirectory);
Directory.GetCurrentDirectory()
returns the path of the directory that the process started from.
The working directory is not necessarily the same as the location of the executable. If you need the location of the actual executable file, you can use Assembly.GetExecutingAssembly().Location
.
string executablePath = Assembly.GetExecutingAssembly().Location; Console.WriteLine("Executable path: " + executablePath);
You can also use the following code to get the directory path of the application executable:
string exePath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
You can also change the working directory using Directory.SetCurrentDirectory()
if needed
- How to get application folder path in C#
- How to copy data to clipboard in C#
- How to mark a method as obsolete or deprecated in C#
- How to Call the Base Constructor in C#
- Deep Copy of Object in C#
- How to Catch Multiple Exceptions in C#
- How to cast int to enum in C#
- What is the difference between String and string in C#?
Categories
Popular Posts
SB Admin Template
11/17/2024
RuangAdmin Template
11/17/2024
DASHMIN Admin Dashboard Template
11/17/2024
K-WD Tailwind CSS Admin Dashboard Template
11/17/2024