Current File Path in C#

To get the current path of a .NET console application in C#:

string currentPath = Environment.CurrentDirectory;

To get the current path of a .NET Winforms application in C#:

string currentPath = Application.StartupPath;

To get the current path of an ASP.NET web application in C#:

string currentPath = Server.MapPath("~");

To get the path of the assembly in which the current code resides in C#:

string currentPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

To get the config file path of the current application in C#:

string configFilePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;

To get the current path of an application's shortcut in C#:

string shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) + "\\YourShortcut.lnk";

To get the full path of the running process in C#:

string currentPath = Process.GetCurrentProcess().MainModule.FileName;

To get the current user's Local Settings folder in C#:

string localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

To get the path to the desktop for the current user in C#:

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
  1. "C# get current file path": Getting the current file path in C#.

    string currentFilePath = System.Reflection.Assembly.GetEntryAssembly().Location;
    
  2. "Getting the current executable path in C#": Retrieving the current executable path in C#.

    string currentExecutablePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
    
  3. "Finding the current file location in C#": Finding the current file location in C#.

    string currentFileLocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
    
  4. "Using Assembly.GetExecutingAssembly().Location in C#": Getting the current file path using Assembly.GetExecutingAssembly().Location in C#.

    string currentFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
    
  5. "Getting the current directory of the executing assembly in C#": Retrieving the current directory of the executing assembly in C#.

    string currentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
    
  6. "Finding the application base directory in C#": Finding the application base directory in C#.

    string appBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
    
  7. "Getting the current script file path in C#": Obtaining the current script file path in C#.

    string currentScriptPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
    
  8. "Using System.Reflection.Assembly.Location to get current file path in C#": Utilizing System.Reflection.Assembly.Location to get the current file path in C#.

    string currentFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
    
  9. "Finding the directory of the entry assembly in C#": Finding the directory of the entry assembly in C#.

    string entryAssemblyDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
    
  10. "Getting the current working directory in C#": Retrieving the current working directory in C#.

    string currentWorkingDirectory = System.IO.Directory.GetCurrentDirectory();
    
  11. "Determining the current script or assembly file name in C#": Determining the current script or assembly file name in C#.

    string currentFileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
    
  12. "Using AppDomain.CurrentDomain.BaseDirectory to get current file path in C#": Using AppDomain.CurrentDomain.BaseDirectory to get the current file path in C#.

    string currentFilePath = AppDomain.CurrentDomain.BaseDirectory;
    
  13. "Finding the location of the running application in C#": Finding the location of the running application in C#.

    string applicationLocation = System.IO.Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
    
  14. "Accessing the current file path in a console application in C#": Accessing the current file path in a console application in C#.

    string currentFilePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;