在 c# windows 应用程序中存储 property.setting 值的位置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/481025/
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
where property.setting value stored in c# windows application
提问by Fred
I thought it should be a config file, but cannot find it. thanks
我认为它应该是一个配置文件,但找不到它。谢谢
采纳答案by George Sealy
If you're talking about .Net settings, then they will normally be in a .config (xml) file in the same directory as the application. When you save them, however, a local copy gets saved in to a user writable folder (typically C:\Users\username\AppData\Local under Vista). Under XP, look in the Documents and Settings folder.
如果您在谈论 .Net 设置,那么它们通常位于与应用程序相同目录中的 .config (xml) 文件中。但是,当您保存它们时,本地副本会保存到用户可写文件夹中(Vista 下通常为 C:\Users\username\AppData\Local)。在 XP 下,查看 Documents and Settings 文件夹。
The .Net application uses this file in preference to the 'default' one in the application directory.
.Net 应用程序优先使用该文件而不是应用程序目录中的“默认”文件。
Hope this helps.
希望这可以帮助。
回答by BFree
Are you referring to the .settings file in your application? When you add values to that file, an app.config file gets created for you. You should be seeing it in your solution explorer.
您指的是应用程序中的 .settings 文件吗?当您向该文件添加值时,会为您创建一个 app.config 文件。您应该会在解决方案资源管理器中看到它。
回答by Greg
On Windows XP, it's stored in a file called user.config in a subfolder of:
在 Windows XP 上,它存储在名为 user.config 的文件中,位于以下子文件夹中:
C:\Documents and Settings\username\Local Settings\Application Data
http://dotnetproject.blogspot.com/2006/08/where-is-userconfig-file-located-in.html
http://dotnetproject.blogspot.com/2006/08/where-is-userconfig-file-located-in.html
回答by el2iot2
The whole config file location can be a bit slippery. Depending on whether or not its a "user" setting or an "application" setting, it will go into a different file. Some settings can even come from your "machine" config (Like in the case of ASP.NET). Instead of guessing where everything is, I find it much more useful to ask .NET where it is looking for these files. Roughly:
整个配置文件的位置可能有点不稳定。根据它是“用户”设置还是“应用程序”设置,它将进入不同的文件。某些设置甚至可以来自您的“机器”配置(例如 ASP.NET)。我发现询问 .NET 在哪里寻找这些文件更有用,而不是猜测一切都在哪里。大致:
//Machine Configuration Path
string path1 = ConfigurationManager.OpenMachineConfiguration().FilePath;
//Application Configuration Path
string path2 = ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None).FilePath;
//User Configuration Path
string path3 = ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
App.Config
应用程序配置
This is what gets added to your project. The build process will name it [myproject].exe.config. This holds the (mostly) read only application settings and the application-level defaults for user-specific settings. Application level settings are difficult to programmatically change their values. Application level setting properties will only have "get" defined. The intention is:if your setting is for all users of the application, then a manual edit (or the installer) should set them. If it changes per user, then make it a per-user setting.
这就是添加到您的项目中的内容。构建过程将其命名为[myproject].exe.config。这保存(大部分)只读应用程序设置和用户特定设置的应用程序级默认值。应用程序级别设置很难以编程方式更改其值。应用程序级别的设置属性将只定义“get”。目的是:如果您的设置适用于应用程序的所有用户,那么手动编辑(或安装程序)应该设置它们。如果它按用户更改,则将其设为每个用户设置。
Binary Default Settings
二进制默认设置
Your application will run without its [myproject].exe.config file. To do this, the binary has its own version of the file "stored". This is useful in some ways, but can be confusing. If you have a .config file in the wrong place or with the wrong name, .NET reverts to the "binary defaults". It can cause the appearance of not being able to affect the settings by changing the config file. Use the method above to know where the .config REALLY goes, or face the wrath of the binary default settings.
您的应用程序将在没有其 [myproject].exe.config 文件的情况下运行。为此,二进制文件有自己的“存储”文件版本。这在某些方面很有用,但可能会令人困惑。如果 .config 文件位于错误的位置或名称错误,.NET 将恢复为“二进制默认值”。它可能会导致无法通过更改配置文件来影响设置的外观。使用上面的方法来了解 .config 的真正去向,或者面对二进制默认设置的愤怒。
User.Config
用户配置
This is generated the first time you "save" your Default.Settings object with a "per-user" setting. This file is saved in the user's profile path in a location based on your project's name, version, operating system, and some other dark .NET magics. The properties for these settings are readable/writeable. They are designed to be easily set and then saved with a single call.
这是在您第一次使用“每个用户”设置“保存”您的 Default.Settings 对象时生成的。该文件保存在用户的配置文件路径中,位置基于项目名称、版本、操作系统和其他一些暗 .NET 魔法。这些设置的属性是可读/可写的。它们旨在轻松设置,然后通过一次调用即可保存。
Pulling it Together
一起拉
So where do my settings go? The answer is that potentially many files are joined together to get the "Active set" of settings. App.config and user.config settings are the basic blocks, but there are machine.config settings, and then there are dependency assembly settings that can further complicate things...but thats another topic entirely.
那么我的设置去哪里了?答案是可能将许多文件连接在一起以获得“活动集”设置。App.config 和 user.config 设置是基本块,但有 machine.config 设置,然后是依赖程序集设置,可以进一步使事情复杂化......但这完全是另一个主题。
The real truth of config files is spread across a lot of ugly cases and details. However, with a little knowledge about how they are joined together, it is a fairly useful system. Especially if you realize you can databind to these settings ;)
配置文件的真相散布在许多丑陋的案例和细节中。然而,只要对它们如何连接在一起有一点了解,它就是一个相当有用的系统。特别是如果你意识到你可以数据绑定到这些设置;)