Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bazen-teklehaymanot/9a83de48be2dd349ddc820c770cdf08c to your computer and use it in GitHub Desktop.
Save bazen-teklehaymanot/9a83de48be2dd349ddc820c770cdf08c to your computer and use it in GitHub Desktop.
C# Environment.SpecialFolder

More info can be found at, https://docs.microsoft.com/en-us/dotnet/api/system.environment.specialfolder?view=netframework-4.7.2

Code example

// C:\ProgramData\
var path1 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.CommonApplicationData);

// C:\Users\USERNAME\AppData\Roaming
var path2 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);

// C:\Users\USERNAME\Documents\
var path3 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);

Generate List

Note that, MyDocuments and Personal are both = 5, so it will appear twice as, MyDocuments

public void OutputPathsTest()
{
  var values = GetValues<System.Environment.SpecialFolder>();
  foreach (var e in values)
  {
    string path = System.Environment.GetFolderPath(e);

    System.Diagnostics.Debug.Print("| " + e.ToString() + " | " + path + " |");
  }
}

private static System.Collections.Generic.IEnumerable<T> GetValues<T>()
{
  return System.Enum.GetValues(typeof(T)).Cast<T>();
}

All enums

SpecialFolder Enum Windows Path Mac Path
AdminTools C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Administrative Tools
ApplicationData C:\Users\USERNAME\AppData\Roaming /Users/USERNAME/.config
CDBurning C:\Users\USERNAME\AppData\Local\Microsoft\Windows\Burn\Burn
CommonAdminTools C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Administrative Tools
CommonApplicationData C:\ProgramData /usr/share
CommonDesktopDirectory C:\Users\Public\Desktop
CommonDocuments C:\Users\Public\Documents
CommonMusic C:\Users\Public\Music
CommonOemLinks
CommonPictures C:\Users\Public\Pictures
CommonProgramFiles C:\Program Files\Common Files
CommonProgramFilesX86 C:\Program Files (x86)\Common Files
CommonPrograms C:\ProgramData\Microsoft\Windows\Start Menu\Programs
CommonStartMenu C:\ProgramData\Microsoft\Windows\Start Menu
CommonStartup C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup
CommonTemplates C:\ProgramData\Microsoft\Windows\Templates
CommonVideos C:\Users\Public\Videos
Cookies C:\Users\USERNAME\AppData\Local\Microsoft\Windows\INetCookies
Desktop C:\Users\USERNAME\Desktop /Users/USERNAME/Desktop
DesktopDirectory C:\Users\USERNAME\Desktop /Users/USERNAME/Desktop
Favorites C:\Users\USERNAME\Favorites /Users/USERNAME/Library/Favorites
Fonts C:\WINDOWS\Fonts /Users/USERNAME/Library/Fonts
History C:\Users\USERNAME\AppData\Local\Microsoft\Windows\History
InternetCache C:\Users\USERNAME\AppData\Local\Microsoft\Windows\INetCache /Users/USERNAME/Library/Caches
LocalApplicationData C:\Users\USERNAME\AppData\Local /Users/USERNAME/.local/share
LocalizedResources
MyComputer
MyDocuments C:\Users\USERNAME\Documents /Users/USERNAME
MyMusic C:\Users\USERNAME\Music /Users/USERNAME/Music
MyPictures C:\Users\USERNAME\Pictures /Users/USERNAME/Pictures
MyVideos C:\Users\USERNAME\Videos
NetworkShortcuts C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Network Shortcuts
Personal C:\Users\USERNAME\Documents /Users/USERNAME
PrinterShortcuts
ProgramFiles C:\Program Files /Applications
ProgramFilesX86 C:\Program Files (x86)
Programs C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
Recent C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Recent
Resources C:\WINDOWS\resources
SendTo C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\SendTo
StartMenu C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu
Startup C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
System C:\WINDOWS\system32 /System
SystemX86 C:\WINDOWS\SysWOW64
Templates C:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Templates
UserProfile C:\Users\USERNAME /Users/USERNAME
Windows C:\WINDOWS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment