Wanting to read a file from my Metro Project / How?

Answered Wanting to read a file from my Metro Project / How?

  • lundi 2 janvier 2012 21:36
     
      A du code

    I have a Metro project that I've put a file in the root directory + "data" called:

    C:\VSProjects\USGov\data\myfile.json

    I want to read this file and can't figure out how to.  I can read files in a temp directory using code like I have below, but I want to include this file in my distribution.  

    Once I figure this out, I'm going to be hit with a second problem which is readString fails with an error on my JSON. How can I read this large json file (.5MB) without getting errors.

     

    dataFile.openAsync(Windows.Storage.FileAccessMode.read).then(function (stream) {
                    var size = stream.size;
                    if (size == 0) {
                        // Data not found
                    }
                    else {
                        var inputStream = stream.getInputStreamAt(0);
                        var reader = new Windows.Storage.Streams.DataReader(inputStream);
    
                        reader.loadAsync(size).then(function () {
                            var contents = reader.readString(size);
    ...
    


     


    Peter Kellner http://peterkellner.net Microsoft MVP • ASPInsider

Toutes les réponses