C# Files (I/O) Examples
C# Basic
C# Data Type
C# OOP
C# IO
C# Graphics & UI
C# Advanced
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);
"C# get current file path": Getting the current file path in C#.
string currentFilePath = System.Reflection.Assembly.GetEntryAssembly().Location;
"Getting the current executable path in C#": Retrieving the current executable path in C#.
string currentExecutablePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
"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);
"Using Assembly.GetExecutingAssembly().Location in C#":
Getting the current file path using Assembly.GetExecutingAssembly().Location
in C#.
string currentFilePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
"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);
"Finding the application base directory in C#": Finding the application base directory in C#.
string appBaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
"Getting the current script file path in C#": Obtaining the current script file path in C#.
string currentScriptPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
"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;
"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);
"Getting the current working directory in C#": Retrieving the current working directory in C#.
string currentWorkingDirectory = System.IO.Directory.GetCurrentDirectory();
"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;
"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;
"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);
"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;