开发者

Loading a configuration file in wpf web application

I have a WPF Browser application in which I am trying to load a config开发者_运维百科uration 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)


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.

StreamResourceInfo sri = Application.GetResourceStream(new Uri(path));

Bad News: You can't load the configuration file into the ConfigurationManager.

Load configuration file from stream instead of file

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜