如何更改 .NET 用户设置位置
默认情况下,设置存储在:C:\Documents and Settings\\Local Settings\Application Data\
如何将此路径更改为应用程序目录。我也不想为不同的用户提供不同的文件。如何使设置全局化?
我尝试将设置的范围更改为“应用程序”,但无法在运行时更改它们。
By default settings are stored at: C:\Documents and Settings\\Local Settings\Application Data\<Project Name>
How can I change this path to application directory. I also don't want to have different files for different users. How make the settings global?
I tried to change the scope of the settings to "application" but then I cannot change them at runtime.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不能使用默认的内置行为!
我同意 Robert Harvey 的回答,请自行操作,或编写自定义设置提供者。
Using the default built-in behavior you can't!
I agree with Robert Harvey's answer do it yourself, or write a custom settings provider.
您始终可以读取和编写自己的 XML 配置文件。
You can always read and write your own XML configuration files.
以编程方式更改所有用户的设置存在困难(因为它们来自 exe.config 文件,该文件通常位于程序文件中,因此在现代操作系统中无法进行写访问)。您可以尝试在应用程序范围内进行设置,然后使用
ConfigurationManager
来处理配置文件,类似于There are difficulties with programmatically changing settings for all users (since they come from the exe.config file, which is usually in Program Files and thus protected from write access in modern OSes). You can try making the settings application-wide but then use the
ConfigurationManager
to mess with the config file, similarly to the solution to this question.