Special paths

Executing path

I sometimes want to get the path of the .exe file that is currently running, usually because I put some folders for logging or configuration there, this is a way to get this path:

// get base directory, entry point
string entryPoint = Assembly.GetEntryAssembly().Location;
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

// create directory name
string configDirectory = Path.Combine(baseDirectory, "config");

Console.WriteLine($"entryPoint:      {entryPoint}");
Console.WriteLine($"baseDirectory:   {baseDirectory}");
Console.WriteLine($"configDirectory: {configDirectory}");
entryPoint:      C:\Users\yourUserName\ConsoleApp\bin\Debug\ConsoleApp.exe
baseDirectory:   C:\Users\yourUserName\ConsoleApp\bin\Debug\
configDirectory: C:\Users\yourUserName\ConsoleApp\bin\Debug\config

https://stackoverflow.com/questions/3991933/get-path-for-my-exe

Special folders

Here is a list of all C# Environment.SpecialFolder:

var allSpecialFolders = Enum.GetValues(typeof(Environment.SpecialFolder)).Cast<Environment.SpecialFolder>();

foreach (Environment.SpecialFolder specialFolder in allSpecialFolders)
{
    Console.WriteLine($"{specialFolder.ToString().PadRight(22)} = {Environment.GetFolderPath(specialFolder)}");
}
Desktop                = C:\Users\yourUserName\Desktop
Programs               = C:\Users\yourUserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
MyDocuments            = C:\Users\yourUserName\Documents
MyDocuments            = C:\Users\yourUserName\Documents
Favorites              = C:\Users\yourUserName\Favorites
Startup                = C:\Users\yourUserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Recent                 = C:\Users\yourUserName\AppData\Roaming\Microsoft\Windows\Recent
SendTo                 = C:\Users\yourUserName\AppData\Roaming\Microsoft\Windows\SendTo
StartMenu              = C:\Users\yourUserName\AppData\Roaming\Microsoft\Windows\Start Menu
MyMusic                = C:\Users\yourUserName\Music
MyVideos               = C:\Users\yourUserName\Videos
DesktopDirectory       = C:\Users\yourUserName\Desktop
MyComputer             =
NetworkShortcuts       = C:\Users\yourUserName\AppData\Roaming\Microsoft\Windows\Network Shortcuts
Fonts                  = C:\WINDOWS\Fonts
Templates              = C:\Users\yourUserName\AppData\Roaming\Microsoft\Windows\Templates
CommonStartMenu        = C:\ProgramData\Microsoft\Windows\Start Menu
CommonPrograms         = C:\ProgramData\Microsoft\Windows\Start Menu\Programs
CommonStartup          = C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
CommonDesktopDirectory = C:\Users\Public\Desktop
ApplicationData        = C:\Users\yourUserName\AppData\Roaming
PrinterShortcuts       =
LocalApplicationData   = C:\Users\yourUserName\AppData\Local
InternetCache          = C:\Users\yourUserName\AppData\Local\Microsoft\Windows\INetCache
Cookies                = C:\Users\yourUserName\AppData\Local\Microsoft\Windows\INetCookies
History                = C:\Users\yourUserName\AppData\Local\Microsoft\Windows\History
CommonApplicationData  = C:\ProgramData
Windows                = C:\WINDOWS
System                 = C:\WINDOWS\system32
ProgramFiles           = C:\Program Files
MyPictures             = C:\Users\yourUserName\Pictures
UserProfile            = C:\Users\yourUserName
SystemX86              = C:\WINDOWS\SysWOW64
ProgramFilesX86        = C:\Program Files (x86)
CommonProgramFiles     = C:\Program Files\Common Files
CommonProgramFilesX86  = C:\Program Files (x86)\Common Files
CommonTemplates        = C:\ProgramData\Microsoft\Windows\Templates
CommonDocuments        = C:\Users\Public\Documents
CommonAdminTools       = C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools
AdminTools             = C:\Users\yourUserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools
CommonMusic            = C:\Users\Public\Music
CommonPictures         = C:\Users\Public\Pictures
CommonVideos           = C:\Users\Public\Videos
Resources              = C:\WINDOWS\resources
LocalizedResources     =
CommonOemLinks         =
CDBurning              = C:\Users\yourUserName\AppData\Local\Microsoft\Windows\Burn\Burn

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s