How to retrieve the Executable Path in C#
By FoxLearn 7/3/2024 9:30:22 AM 137
Here’s how to retrieve the Executable Path in C#
// c# get the full path to the currently executing assembly string exePath = System.Reflection.Assembly.GetExecutingAssembly().Location; Console.WriteLine("Executable Path: " + exePath);
Use the System.Reflection.Assembly.GetExecutingAssembly()
method to retrieve the assembly that contains the code that is currently executing.
Using .Location
gives you the full path to the location of the assembly file.
If you want to retrieve the base directory of the executable without using the Reflection
namespace, you can directly access it through the AppDomain
class.
// c# get the base directory of the executable string baseDir = AppDomain.CurrentDomain.BaseDirectory; Console.WriteLine("Base Directory: " + baseDir);
Using AppDomain.CurrentDomain.BaseDirectory
gives you the base directory where the executable is located. It's often preferred over using System.Reflection.Assembly.GetExecutingAssembly().Location
when all you need is the base directory of the executable .
- How to Read data from Google Sheet in C# using HttpRequest without Speadsheet API
- How to set DataSource for RDLC Report using Report Viewer in C#
- How to Change report in ReportViewer at runtime in C#
- C# Tutorial
- How to Create overlay modal popup in C#
- How to check if file exists on Server in C#
- How to encrypt a password in C#
- How to read excel file in C#