I'm trying to set up a config file for some app-specific items (such as API keys) for my WinRT experiment.
So far I added a "config.xml" file to the root of my project, marked it as a resource in the properties... and then I'm stuck.
Every example I can find seems to deal with JSON resource files (which are somehow tied to localization by convention and don't seem to be appropriate for general config stuff?), loading files from disk (which doesn't work since resources get compiled into the .pri file), or uses C#.
So how can I make this work in my Javascript/HTML5 app?
My latest attempt was this:
var uri = new Windows.Foundation.Uri('ms-resource:///config');
var xml = Windows.ApplicationModel.Resources.ResourceLoader
.getStringForReference(uri);
but this doesn't work and throws the following exception:
0x80073b1f - JavaScript runtime error: ResourceMap Not Found.
What am I missing?
var r = Windows.ApplicationModel.Resources.Core.ResourceManager
.current.mainResourceMap.lookup('Files/config.xml');
var candidates = r.resolveAll();
candidates[0].getValueAsFileAsync().done(readXml);
This finds the file resource, but all the candidate contains is the original absolute path to the file, so getValueAsFileAsync()
throws an exception saying "The system cannot find the file specified." (and the readXml
callback isn't called).
So I still can't seem to get at the contents of this XML file.
Try this...
var uri = new Windows.Foundation.Uri('ms-appx:///myFolder/myConfig.xml');
var file = Windows.Storage.StorageFile.getFileFromApplicationUriAsync(uri);
You can now use the file to parse and handle the data as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With