locked
Trouble accessing ApplicationData from x-ms-webview.

    Question

  • I am working on an app that lets users edit their documents. When user edits a document, a html based editor is opened in another x-ms-webview. For editor to work it needs to read some files containing JSON data from disk at runtime. For that i have used following code:

    var test = 'WebEditor\\SmartDoc\\Schema.json';
                    var file = Windows.Storage.ApplicationData.current.localFolder.getFileAsync(test).then(function (e) {
                        e.openReadAsync().then(function (inputStream)
                        {
                            var reader = new Windows.Storage.Streams.DataReader(inputStream);
                            var size = inputStream.size
                            reader.loadAsync(size).then(function () {
                                var contents = JSON.parse(reader.readString(size));
                                console.log(contents);
                            });
                            
                        })
                        
                    }, function (e) {
                        console.log("error");
                    });

    This code works as long as i am inside page which is running under MSAppHost user agent. Editor which is opened in x-ms-webview has different user agent "WebView" where i dont have access to "Windows" object. So, above code does not work in x-ms-webview. Can any one tell me what i am missing here? I am new to WinJS.



    • Edited by asingh86 Wednesday, January 07, 2015 1:04 PM
    Wednesday, January 07, 2015 12:58 PM

Answers

  • Hi asingh86,

    As I know you can navigate to some HTML string by navigateToString method.

    Here is the work around but I don't know if I misunderstand something.

    #1, Read your HTML string

    #2, Read your Json data and insert to the HTML string

    #3, Display the HTML in the x-ms-webview control.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 08, 2015 7:49 AM
    Moderator