431

How do I get a path to the desktop for current user in C#?

The only thing I could find was the VB.NET-only class SpecialDirectories, which has this property:

My.Computer.FileSystem.SpecialDirectories.Desktop

How can I do this in C#?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Cristian Diaconescu
  • 34,633
  • 32
  • 143
  • 233

2 Answers2

935
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • The items returned from this folder is different to what Window Explorer shows. E.g. in my XP, it doesn't include My Documents, My Computer, My Network Places, Recycle Bin and some other shortcuts. Any idea how to get the same entries as Windows Explorer? – newman Mar 21 '13 at 20:24
  • 9
    Maybe you are looking for SpecialFolder.DesktopDirectory? This is the physical folder instead of the logical. – gimlichael Jul 05 '13 at 10:28
  • 2
    This returns me the admin user desktop if the program is run as admin – mrid Sep 18 '19 at 08:07
34
// Environment.GetFolderPath
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); // Current User's Application Data
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData); // All User's Application Data
Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles); // Program Files
Environment.GetFolderPath(Environment.SpecialFolder.Cookies); // Internet Cookie
Environment.GetFolderPath(Environment.SpecialFolder.Desktop); // Logical Desktop
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); // Physical Desktop
Environment.GetFolderPath(Environment.SpecialFolder.Favorites); // Favorites
Environment.GetFolderPath(Environment.SpecialFolder.History); // Internet History
Environment.GetFolderPath(Environment.SpecialFolder.InternetCache); // Internet Cache
Environment.GetFolderPath(Environment.SpecialFolder.MyComputer); // "My Computer" Folder
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // "My Documents" Folder
Environment.GetFolderPath(Environment.SpecialFolder.MyMusic); // "My Music" Folder
Environment.GetFolderPath(Environment.SpecialFolder.MyPictures); // "My Pictures" Folder
Environment.GetFolderPath(Environment.SpecialFolder.Personal); // "My Document" Folder
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); // Program files Folder
Environment.GetFolderPath(Environment.SpecialFolder.Programs); // Programs Folder
Environment.GetFolderPath(Environment.SpecialFolder.Recent); // Recent Folder
Environment.GetFolderPath(Environment.SpecialFolder.SendTo); // "Sent to" Folder
Environment.GetFolderPath(Environment.SpecialFolder.StartMenu); // Start Menu
Environment.GetFolderPath(Environment.SpecialFolder.Startup); // Startup
Environment.GetFolderPath(Environment.SpecialFolder.System); // System Folder
Environment.GetFolderPath(Environment.SpecialFolder.Templates); // Document Templates
David Buck
  • 3,752
  • 35
  • 31
  • 35
Xiaohuan ZHOU
  • 478
  • 5
  • 6