如何访问 Windows 中的特殊目录?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3671404/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 15:13:08  来源:igfitidea点击:

How do I access special directories in Windows?

c#.netwindows

提问by spig

What is the C# syntax to retrieve the user's desktop, documents folder and other system folders on windows?

在 Windows 上检索用户桌面、文档文件夹和其他系统文件夹的 C# 语法是什么?

回答by Reed Copsey

You can use Environment.GetFolderPathwith the Environment.SpecialFolderenumeration. For example:

您可以将Environment.GetFolderPathEnvironment.SpecialFolder枚举一起使用。例如:

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

回答by Aliostad

Use:

用:

string folder = Environment.GetFolderPath(Environment.SpecialFolder.*);

Where * is one of the enum values.

其中 * 是枚举值之一。

回答by Jonathan

System.Environment.SpecialFolder.MyComputer

etc.

等等。