如何在 C# 中获取当前用户的本地设置文件夹路径?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/57350/
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
How do I get the current user's Local Settings folder path in C#?
提问by Luke
I want to point a file dialog at a particular folder in the current user's Local Settings folder on Windows. What is the shortcut to get this path?
我想在 Windows 上当前用户的本地设置文件夹中的特定文件夹中指向一个文件对话框。获取此路径的快捷方式是什么?
采纳答案by Matthew Maravillas
How about this, for example:
这个怎么样,例如:
String appData =
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
I don't see an enum for just the Local Settings folder.
我没有看到仅本地设置文件夹的枚举。
http://web.archive.org/web/20080303235606/http://dotnetjunkies.com/WebLog/nenoloje/archive/2007/07/07/259223.aspxhas a list with examples.
回答by Darren Kopp
Environment.GetFolderPath( Environment.SpecialFolders.LocalApplicationData);?
Environment.GetFolderPath(Environment.SpecialFolders.LocalApplicationData);?
I can't remember if there is a "Local Settings" folder on Windows XP anymore, it seems vaguely familiar.
我不记得 Windows XP 上是否有“本地设置”文件夹,似乎有点眼熟。
回答by nawfal
string localPath = Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)).FullName;
is the simple answer.
是简单的答案。