【问题标题】:Grabbing current user.config path (Visual Basic)获取当前 user.config 路径 (Visual Basic)
【发布时间】:2020-05-14 00:20:13
【问题描述】:

有没有办法获取 My.Settings user.config 位置的位置?因此,例如,我希望能够在 VB 中将 user.cofing 文件路径的路径获取到字符串

我问的原因是我有一个应用程序,其中 user.config 文件被备份然后恢复,问题是 my.settings 文件夹结构它使用具有文件夹名称的唯一哈希,这意味着我不能将静态文件夹路径写入代码,而不是我需要能够获取 user.config 的位置 或 能够获取应用程序 AppData 的文件夹名称。

有什么想法吗?

从这个角度来看,目前我正在使用这样的东西:

将文件路径变暗为字符串

        filePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\My_App\My_App.exe_Url_<the_hash_that_changes_causing_issues>\1.0.0.0\user.config"

由于哈希更改,这并不总是有效

【问题讨论】:

  • 什么样的应用程序?

标签: vb.net basic my.settings


【解决方案1】:

尝试执行这段代码:

Dim mainConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
Dim userConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoaming)
Dim userLocalConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)

Console.WriteLine(mainConfig.FilePath)
Console.WriteLine(userConfig.FilePath)
Console.WriteLine(userLocalConfig.FilePath)

您需要引用 System.Configuration.dll 并导入 System.Configuration。

【讨论】:

    猜你喜欢
    • 2012-02-28
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 2016-09-01
    • 2010-09-10
    • 2018-04-13
    • 2018-11-03
    • 2020-04-16
    相关资源
    最近更新 更多