如何以编程方式获取 user.config 文件的位置?
我想在 Windows 窗体应用程序中显示 user.config 文件的位置,以便用户可以轻松找到它。
我了解路径是如何创建的,这要归功于: 我可以控制 .NET 用户设置的位置以避免在应用程序升级时丢失设置吗?。
但是,如果这种情况发生变化,我宁愿不必在我的应用程序中构建路径,特别是如果有一种简单的方法来获取 user.config 文件位置。
I'd like to display the location of the user.config file in my windows forms application so a user can easily find it.
I understand how the path is created thanks to: Can I control the location of .NET user settings to avoid losing settings on application upgrade?.
However, in case this changes, I would rather not have to construct path this in my app, especially if there is an easy method for getting the user.config file location.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
Try this:
根据应用程序的运行方式,ConfigurationUserLevel.PerUserRoamingAndLocal 可能是您正在寻找的属性,而不是 ConfigurationUserLevel.PerUserRoaming;
即:
请确保在项目引用中包含 System.Configuration 才能使用它。
Depending on how your application runs, ConfigurationUserLevel.PerUserRoamingAndLocal may be the property you're looking for rather than ConfigurationUserLevel.PerUserRoaming;
i.e:
Be sure to have System.Configuration in your project's references in order to use this.
使用
ConfigurationManager
获取Configuration
对象。Configuration
对象有一个字符串属性FilePath
。请参阅:配置成员
Use the
ConfigurationManager
to get theConfiguration
-object. TheConfiguration
-object has a string propertyFilePath
.See: Configuration-Members