How to find the desktop on any user computer?
How can I find the deskt开发者_运维问答op or my documents on any user computer
(I don't know the computer name)
You could use the Environment.GetFolderPath method which will return you the path to the corresponding special folder passed as enum argument. Example:
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
You can do find it easily using Environment.SpecialFolder enum.
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
The Environment.SpecialFolder enumeration has everything you need.
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx
http://msdn.microsoft.com/en-us/library/14tx8hby.aspx
Use the Environment.SpecialFolder
Enumeration together with Environment.GetFolderPath()
method, for example:
var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
This returns the path of the desktop of the currently logged in user. If you want to retrieve the path of the desktop folder for all users, use this instead:
var desktopPath =
Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
精彩评论