Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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#?

like image 946
Cristian Diaconescu Avatar asked Mar 11 '09 11:03

Cristian Diaconescu


People also ask

How do I find the path to my Desktop?

In the navigation pane on the left side, right-click Desktop and select Properties. In the Properties window, click the Location tab. The directory path to the desktop is displayed in the text field on the Location tab.

What is the path for Desktop in Linux?

In your case and everybody else, the Desktop folder is normally in the /home/username/Desktop . So if you open the terminal and you are already in your user directory, for example /home/username then you only need to just type cd Desktop because you are already in the directory where desktop is.

What is the path for Desktop in Windows 7?

Answers. C:\Users\Public\Desktop is the default path.


2 Answers

string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
like image 179
Marc Gravell Avatar answered Oct 03 '22 06:10

Marc Gravell


// 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
like image 25
Xiaohuan ZHOU Avatar answered Oct 03 '22 08:10

Xiaohuan ZHOU