C# Properties.Settings.Default 存储在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/982354/
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-06 04:50:18  来源:igfitidea点击:

Where are the Properties.Settings.Default stored?

c#.netsettings

提问by DaveN59

I thought I knew this, but today I'm being proven wrong - again.

我以为我知道这一点,但今天我再次被证明是错误的。

Running VS2008, .NET 3.5 and C#. I added the User settings to the Properties Settings tab with default values, then read them in using this code:

运行 VS2008、.NET 3.5 和 C#。我使用默认值将用户设置添加到属性设置选项卡,然后使用以下代码读取它们:

myTextBox.Text = Properties.Settings.Default.MyStringProperty;

Then, after the user edits the value in the options dialog I save it like this:

然后,在用户编辑选项对话框中的值后,我将其保存如下:

Properties.Settings.Default.MyStringProperty = myTextBox.Text;
Properties.Settings.Default.Save();

My question is, where is this new value saved? the MyApp.exe.config file in the executable directory is not updated, it still contains the default values. Plus, as far as I can tell, none of the other files in that directory are updated either! However, when the program reads the value back in, it gets the changed value, so I know it's saved somewhere...

我的问题是,这个新值保存在哪里?可执行目录中的 MyApp.exe.config 文件没有更新,它仍然包含默认值。另外,据我所知,该目录中的其他文件也没有更新!但是,当程序读回该值时,它会获取更改后的值,所以我知道它已保存在某处...

This isn't just academic, I needed to be able to manually edit the value this morning and got myself stumped when I couldn't find anything that was changing.

这不仅仅是学术问题,今天早上我需要能够手动编辑该值,当我找不到任何正在改变的东西时,让自己难住了。

采纳答案by jasonh

In order to work with newer versions of Windows' policy of only allowing read access by default to the Program Files folder (unless you prompt for elevation with UAC, but that's another topic...), your application will have a settings folder under %userprofile%\appdata\localor %userprofile%\Local Settings\Application Datadepending on which version of Windows you're running, for settings that are user specific. If you store settings for all users, then they'll be in the corresponding folder under C:\usersor C:\Documents and Settingsfor all user profiles (ex: C:\users\public\appdata\local).

为了使用较新版本的 Windows 策略,默认情况下只允许对 Program Files 文件夹进行读取访问(除非您提示使用 UAC 进行提升,但这是另一个主题...),您的应用程序将在%userprofile%\appdata\local%userprofile%\Local Settings\Application Data对于特定于用户的设置,取决于您运行的 Windows 版本。如果您为所有用户存储设置,则它们将位于所有用户配置文件下C:\usersC:\Documents and Settings所有用户配置文件(例如:)下的相应文件夹中C:\users\public\appdata\local

回答by Joel Coehoorn

User-specific settings are saved in the user's Application Data folder for that application. Look for a user.configfile.

用户特定的设置保存在该应用程序的用户应用程序数据文件夹中。寻找一个user.config文件。

I don't know what you expected, since users often don't even have write access to the executable directory in the first place.

我不知道您期望什么,因为用户通常一开始甚至没有对可执行目录的写访问权限。

回答by J.W.

There is a folder called "Properties" under your project root folder, and there are *.settings file under that folder. That's where it gets stored.

在您的项目根文件夹下有一个名为“Properties”的文件夹,该文件夹下有一个 *.settings 文件。那就是它被存储的地方。

回答by Stan R.

it is saved in your Documents and Settings\%user%\Local Settings\Application Data......etc search for a file called user.configthere

它保存在您的 Documents and Settings\%user%\Local Settings\Application Data......etc 中,在那里搜索名为user.config的文件

the location may change however.

然而,位置可能会改变。

回答by Akbaritabar

You can get the path programmatically:

您可以通过编程方式获取路径:

using System.Configuration;  // Add a reference to System.Configuration.dll
...
var path = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;

回答by Jeremy Ehret

thanks for pointing me in the right direction. I found user.config located at this monstrosity: c:\users\USER\AppData\Local\COMPANY\APPLICATION.exe_Url_LOOKSLIKESOMEKINDOFHASH\VERSION\user.config.

感谢您为我指明正确的方向。我发现 user.config 位于这个怪物:c:\users\USER\AppData\Local\COMPANY\APPLICATION.exe_Url_LOOKSLIKESOMEKINDOFHASH\VERSION\user.config。

I had to uprev the version on my application and all the settings seemed to have vanished. application created a new folder with the new version and used the default settings. took forever to find where the file was stored, but then it was a simple copy and paste to get the settings to the new version.

我不得不在我的应用程序上升级版本,所有设置似乎都消失了。应用程序使用新版本创建了一个新文件夹并使用默认设置。花了很长时间才能找到文件的存储位置,但是只需简单的复制和粘贴即可将设置设置为新版本。

回答by EvilDuck

One of my windows services is logged on as Local System in windows server 2016, and I can find the user.config under C:\Windows\SysWOW64\config\systemprofile\AppData\Local\{your application name}.

我的一个 Windows 服务在 windows server 2016 中作为本地系统登录,我可以在 C:\Windows\SysWOW64\config\systemprofile\AppData\Local\{您的应用程序名称} 下找到 user.config。

I think the easiest way is searching your application name on C drive and then check where is the user.config

我认为最简单的方法是在 C 驱动器上搜索您的应用程序名称,然后检查 user.config 在哪里

回答by Lukas

For anyone wondering where the settings for apps from the Microsoft Store are, they are either in WindowsApps, which is very locked down, but you can get there by opening your app and then opening the file path with Task-Manager.

对于任何想知道 Microsoft Store 中应用程序设置在哪里的人来说,它们要么位于 WindowsApps 中,该应用程序被非常锁定,但您可以通过打开您的应用程序然后使用任务管理器打开文件路径来到达那里。

But it's more likely that they are saved in C:\Users\[USERNAME]\AppData\Local\Packages\[NUMBERS][COMPANY].[APPLICATION]_[RANDOMDATA]\LocalCache\Local\[COMPANY]\[APPLICATION].exe_Url_[RANDOMDATA]\[VERSION]\user.config.

但更有可能他们被保存在C:\Users\[USERNAME]\AppData\Local\Packages\[NUMBERS][COMPANY].[APPLICATION]_[RANDOMDATA]\LocalCache\Local\[COMPANY]\[APPLICATION].exe_Url_[RANDOMDATA]\[VERSION]\user.config.