【问题标题】:Find location of user.confi?查找 user.config 的位置?
【发布时间】:2016-08-05 22:53:22
【问题描述】:

我知道已经有一些关于此的问题,但没有一个对我有帮助。

所以我有一个 .NET c# 应用程序,它的 app.config 中有这样的设置:

  <userSettings>
    <MyApp.Client.Main.Properties.Settings>
      <setting name="LoginSwitchUserRestart" serializeAs="String">
        <value>False</value>
      </setting>
      <setting name="SkinName" serializeAs="String">
        <value>Blue</value>
      </setting>
    </MyApp.Client.Main.Properties.Settings>
  </userSettings>

这是假设保存在位于此处的文件中 C:\Users\Me\AppData\Roaming\MyCompany_Healthcare_Systems_A\MyApp.vshost.exe_Url_fch0ekqas3qxil4p11igflywwa1klvng\5.8.0.0\user.config

根据这段代码:

var config = System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoaming);

MessageBox.Show(config.FilePath);

但是没有文件?我也有这个应用程序的多个版本在 Visual Studio 内部和外部作为发布版本运行,但我仍然找不到设置文件?

操作系统为 Windows 10 64 位。

【问题讨论】:

  • 我没有想到去哪里看 - 所以我做了一个测试,我的在 appdata\\appname.exe_\\user.config - 我想知道如果这有助于以编程方式找到它(尚未检查)stackoverflow.com/questions/793657/…
  • 在我的 appdata 下,我只有漫游、本地和本地低。现在在本地查看时,我可以看到我的公司文件夹和 user.config!?
  • 抱歉,它在本地...所以,问题是我们可以根据stackoverflow.com/questions/621265/… user.config 以编程方式获取它吗? user.config 将永远是我找到它的地方.. 但猜测哈希并不是真的可行的。还在寻找

标签: c# .net settings config app-config


【解决方案1】:

您可以添加对 System.configuration 的引用并将其用于使用

ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath

这会返回 user.config 的路径

【讨论】:

    猜你喜欢
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 2014-05-01
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多