在 wpf Web 应用程序中加载配置文件
我有一个 WPF 浏览器应用程序,我试图在其中加载配置文件。
由于应用程序部署为 xbap,它无法访问本地文件系统,因此我需要将配置文件编译为程序集中的资源。
现在,我无法在浏览器应用程序中加载配置文件,因为 ExeConfiguationFileMap 类仅采用文件系统路径而不是 Pack URI。
我该如何解决这个问题?
这就是我的代码的样子。
let filemap = new ExeConfigurationFileMap()
filemap.ExeConfigFilename <- (new System.Uri(@"pack://application:,,,/PSAT.PSATResources;component\resources\config\app.config")).LocalPath
TMDBConnection.m_config <- System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(filemap, System.Configuration.ConfigurationUserLevel.None)
I have a WPF Browser application in which I am trying to load a configuration file.
As the application is deployed as an xbap it does not have access to the the local filesystem and therefore I need to compile the config file as a resource within the assembly.
Now, I am not able to load the config file in the browser application as the ExeConfiguationFileMap class only takes a file system path not a Pack URI.
How do I resolve this issue?
This is what my code looks like.
let filemap = new ExeConfigurationFileMap()
filemap.ExeConfigFilename <- (new System.Uri(@"pack://application:,,,/PSAT.PSATResources;component\resources\config\app.config")).LocalPath
TMDBConnection.m_config <- System.Configuration.ConfigurationManager.OpenMappedExeConfiguration(filemap, System.Configuration.ConfigurationUserLevel.None)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好消息:
这会将您的配置文件加载到流(sri.Stream)中,您可以从中解析配置文件并读取您需要的值。
坏消息:
您无法将配置文件加载到 ConfigurationManager 中。
从流而不是文件加载配置文件
Good News:
This will load your config file into a stream (sri.Stream), from which you can parse the config file and read the values that you need.
Bad News:
You can't load the configuration file into the ConfigurationManager.
Load configuration file from stream instead of file