如何在 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

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

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.

http://web.archive.org/web/20080303235606/http://dotnetjunkies.com/WebLog/nenoloje/archive/2007/07/07/259223.aspx有一个包含示例的列表。

回答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.

是简单的答案。