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


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


    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( (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 Microsoft MVP • ASPInsider
    2. ledna 2012 21:36


  • Hi Jeff,

    "StorageFile                 sf = await Package.Current.InstalledLocation.GetFileAsync" means nothing to me.  Is Package a namespace? it does not show up in the WinRT api list for JavaScript (or c# for that matter which is where it is posted).

    Can you please give me an example in JavaScript similar to my code above that will allow me to open and read the file.  I combined it in one questions because open and read are usually together in the same example.  If you still want me to create another thread for this question I will but to me it seems unnecesary.

    Peter Kellner Microsoft MVP • ASPInsider
    3. ledna 2012 16:39
  • Sorry Peter I go back and forth between the two I forgot where you were posting and put in the C# thread.

    The documentation has an example of how to use these objects for each language (normally).

    Here is the documentation for that API:

    You should be able to use that the same way you are using storage folders in javascript today.

    If you need some examples for using storage folders, check out the documentation or samples and they should help you along (any of the picker examples should be adequate!


    Jeff Sanders (MSFT)
    3. ledna 2012 16:49

Všechny reakce