如何在C#中为当前用户获取桌面路径?

如何在C#中为当前用户获取桌面路径?,c#,windows,filesystems,directory,C#,Windows,Filesystems,Directory,如何在C#中获取当前用户的桌面路径 我唯一能找到的是VB.NET-only类,它具有以下属性: My.Computer.FileSystem.SpecialDirectories.Desktop 如何在C#中执行此操作?此文件夹返回的项目与Windows资源管理器显示的项目不同。例如,在我的XP中,它不包括我的文档、我的计算机、我的网络位置、回收站和其他一些快捷方式。知道如何获得与Windows资源管理器相同的条目吗?也许您正在寻找SpecialFolder.DesktopDirectory?

如何在C#中获取当前用户的桌面路径

我唯一能找到的是VB.NET-only类,它具有以下属性:

My.Computer.FileSystem.SpecialDirectories.Desktop

如何在C#中执行此操作?

此文件夹返回的项目与Windows资源管理器显示的项目不同。例如,在我的XP中,它不包括我的文档、我的计算机、我的网络位置、回收站和其他一些快捷方式。知道如何获得与Windows资源管理器相同的条目吗?也许您正在寻找SpecialFolder.DesktopDirectory?这是物理文件夹,而不是逻辑文件夹。如果程序以管理员身份运行,则返回管理员用户桌面admin@Emma我记得-没问题
string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
// 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