locked
Error reading from a file.

    Question

  • Here is my code:

    var package1 = Windows.ApplicationModel.Package.current;
                    var installedLocation = package1.installedLocation;
    
                    installedLocation.getFileAsync("myList.com.txt")
                        .then(function (myFile) {
                            Windows.Storage.FileIO.readTextAsync(myFile).then(function (myText) {
                                
                                var msg1 = new Windows.UI.Popups.MessageDialog("Success").showAsync();
                            }, function () {
                                Windows.UI.Popups.MessageDialog("MiddleError").showAsync();
                            });
                        }, function () {
                            var messageDialog = new Windows.UI.Popups.MessageDialog("Error"); messageDialog.showAsync();
                        });

    The middleError keeps popping up.

    Any ideas?

    Thanks

    Sunday, February 24, 2013 7:37 AM

Answers


  • Hi,

    I've tried the following test code which works in my local test windows store app (html5+ javascript). The file is directly added at root of the project.


    _readFileInPackage: function(){
        var folder = Windows.ApplicationModel.Package.current.installedLocation;
        folder.getFileAsync("mylist.com.txt").then(
            function (file) {
                return Windows.Storage.FileIO.readTextAsync(file);
            }
        ).done(
            function (data) {
                console.log("txt data: " + data);
            },
            function (err) {
                console.log("Error: " + err);
            }
        );
    }



    I'd suggest you try debugging the app and set breakpoint into the error callback function so that you can check the detailed error info against the error object passed in the callback function. Also, you can get the path of the "Windows.ApplicationModel.Package.current.installedLocation" folder when breaking in the debugger and go to the folder in file explorer to see if the file does exists in the folder.

     

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 25, 2013 3:44 AM
    Moderator

All replies


  • Hi,

    I've tried the following test code which works in my local test windows store app (html5+ javascript). The file is directly added at root of the project.


    _readFileInPackage: function(){
        var folder = Windows.ApplicationModel.Package.current.installedLocation;
        folder.getFileAsync("mylist.com.txt").then(
            function (file) {
                return Windows.Storage.FileIO.readTextAsync(file);
            }
        ).done(
            function (data) {
                console.log("txt data: " + data);
            },
            function (err) {
                console.log("Error: " + err);
            }
        );
    }



    I'd suggest you try debugging the app and set breakpoint into the error callback function so that you can check the detailed error info against the error object passed in the callback function. Also, you can get the path of the "Windows.ApplicationModel.Package.current.installedLocation" folder when breaking in the debugger and go to the folder in file explorer to see if the file does exists in the folder.

     

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 25, 2013 3:44 AM
    Moderator
  • Thanks,

    As you can see from my code, I'm new to this.  The error was caused by an unusual single-quote within the file.  When the quotes were replaced with regular single-quotes. there was no read error.  I'm still not sure what that was all about.

    I did learn from you the console.log instead of Windows.UI.Popups...., so thank you for that.

    Monday, February 25, 2013 6:26 AM